PhpExcel output xls file display garbled solution recently some reporting systems are working on, mainly reading and processing excel. There was no garbled code during the previous development on my own machine, even if I arranged it on the server and imported it, no garbled characters were found in exported excel files. later, I installed it on a colleague's machine, but it was very depressing. later, phpExcel output the xls document to display garbled solutions.
Recently, some reporting systems mainly read and process excel.
No gibberish occurs during development on your own machine,
Even if I deploy it on the server, the import and export of excel files are not garbled.
Later, I installed my computer on a colleague, but it was messy,
Then I read a blog post on the Internet and solved the problem.
?
$ Filename = urlencode ("tax table .xls"); header ('content-Type: application/vnd. ms-excel '); header ('content-Disposition: attachment; filename = '. $ filename); header ('cache-Control: max-age = 0'); $ objWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, 'excel5 '); $ objWriter-> save ('php: // output ');
?
I wrote it like this, but garbled characters appear on some machines.
?
I changed it to the following one.
?
$ Filename = urlencode ("tax table .xls"); ob_end_clean (); header ('content-Type: application/vnd. ms-excel '); header ('content-Disposition: attachment; filename = '. $ filename); header ('cache-Control: max-age = 0'); $ objWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, 'excel5 '); $ objWriter-> save ('php: // output ');
?
Added ob_end_clean (). the cache is cleared before the xls file is output. No problem.
On the first floor, telankes2000 2012-05-31 is useful. can you explain the reason? On the second floor, yeyuan 2012-05-31 telankes2000 wrote that it was useful to explain why?
There should be some other data output before the table's data output! Clear the file first, and then output the file.