- /**
- * Export an excel file
- * By bbs.it-home.org
- */
- Function xlsBOF (){
- Echo pack ("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0 );
- Return;
- }
- Function xlsEOF (){
- Echo pack ("ss", 0x0A, 0x00 );
- Return;
- }
- Function xlsWriteNumber ($ Row, $ Col, $ Value ){
- Echo pack ("sssss", 0x203, 14, $ Row, $ Col, 0x0 );
- Echo pack ("d", $ Value );
- Return;
- }
- Function xlsWriteLabel ($ Row, $ Col, $ Value ){
- $ Value = iconv ("UTF-8", "gb2312", $ Value); // add this statement to solve the problem of exporting garbled excel files 20110629
- $ L = strlen ($ Value );
- Echo pack ("ssssss", 0x204, 8 + $ L, $ Row, $ Col, 0x0, $ L );
- Echo $ Value;
- Return;
- }
- Include "connection. php ";
- $ SQL = "select ledger_name, ledger_sex, ledger_age, ledger_add from ps_ledger_11 ";
- $ Query = mysql_query ($ SQL );
- // File header
- Header ("Pragma: public ");
- Header ("Expires: 0 ");
- Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");
- Header ("Content-Type: application/force-download ");
- Header ("Content-Type: application/octet-stream ");
- Header ("Content-Type: application/download ");
- Header ("Content-Type: application/vnd. ms-excel; charsets = UTF-8 ");
- Header ("Content-Disposition: attachment?filename=auxiliary police force statistical table .xls ");
- // Header ("Content-Disposition: inline; filename = \" ". $ filename.". xls \"");
- // Iconv ("UTF-8", "gb2312", $ filename); // Fix the garbled characters caused by Files ". xls \"");
- Header ("Content-Transfer-Encoding: binary ");
- // Add data to the table
- XlsBOF ();
- XlsWriteLabel (1, 0, "column name ");
- XlsWriteLabel (1, 1, "column name ");
- XlsWriteLabel (1, 2, "column name ");
- XlsWriteLabel (1, 3, "column name ");
- XlsWriteLabel (1, 4, "column name ");
- $ XlsRow = 1;
- While ($ array = mysql_fetch_array ($ query )){
- ++ $ I;
- XlsWriteNumber ($ xlsRow, 0, "$ I ");
- XlsWriteNumber ($ xlsRow, 0, "$ array [0]");
- XlsWriteLabel ($ xlsRow, 1, "$ array [1]");
- XlsWriteLabel ($ xlsRow, 2, "$ array [2]");
- XlsWriteLabel ($ xlsRow, 3, "$ array [3]");
- XlsWriteLabel ($ xlsRow, 4, "$ array [4]");
- $ XlsRow ++;
- }
- XlsEOF ();
- Exit ();
- // 20110629 the test passes in the evening. The column name cannot be displayed? Others.
- ?>
|