-
- /**
- * Export 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 garbled problem of exported 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; charset=UTF-8");
- header("Content-Disposition: attachment;filename=Police Office Auxiliary Police Statistics Table.xls ") ;
- //header("Content-Disposition: inline; filename="" . $filename . ".xls"");
- //iconv("utf-8", "gb2312", $filename);//Solution 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 Test passed at night . Column names are not displayed? Others are OK.
- ?>
Copy code
|