- <?php 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 ) { $L = strlen($Value); echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); echo $Value; return; } include "开启数据库文件"; $sql = "select * from table"; $query = mysql_query($sql); // 文件头 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-Disposition: attachment;filename=456.xls "); header("Content-Transfer-Encoding: binary "); // 向表中添加数据 xlsBOF(); xlsWriteLabel(0,0,"列名"); xlsWriteLabel(0,1,"列名"); xlsWriteLabel(0,2,"列名"); xlsWriteLabel(0,3,"列名"); xlsWriteLabel(0,4,"列名"); $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(); ?>
[转帖] 将数据导出成为excle格式
最新推荐文章于 2024-11-06 11:25:59 发布