03
7
phpexcel貌似强大,不过很复杂.唯有用简单的方法,试了几个代码.能导出excel,但是会出现乱码.最后还是用iconv才解决掉.另外header(“Content-type:charset=utf-8″);是无法解决的.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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:charset=utf-8"); header("Content-Type: application/download");; header("Content-Disposition: attachment;filename=".$post['time1']."-".$post['time2'].".xls "); header("Content-Transfer-Encoding: binary "); xlsBOF(); xlsWriteLabel(1,0,"文字测试"); xlsWriteNumber(2,0,123); xlsEOF(); 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);//由于网页编码是UTF-8,需要用iconv转码.否则乱码 $L = strlen($Value); echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); echo $Value; return; } |
当前没有评论!
第一个在本文留言。