PhpExcel output xls file display garbled solution

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.