How to export excel files in php and solve garbled text

Source: Internet
Author: User
How to export excel files in php and solve garbled text

  1. Header ("Content-type: application/vnd. ms-excel ");
  2. Header ("Content-Disposition: attachment?filename=export_data.xls ");
  3. Echo "name". "\ t ";
  4. Echo "traditional". "\ t ";
  5. Echo "blog". "\ t ";
  6. Echo "\ n ";
  7. Echo "jason". "\ t ";
  8. Echo "@". "\ t ";
  9. Echo "javaeye". "\ t ";
  10. ?>

Consider adding the character set header ("Content-type: application/vnd. ms-excel; charset = UTF-8") to the header ");

Question: I only want to tell the browser which character set to choose to view. In the end, I still need to generate xls files. some friends suggest iconv transcoding.

  1. Echo iconv ("current code", "GB18030", "This blog is from javaeye, by jason ");

Q: In this case, the Chinese character encoding in the file is GB18030. but what encoding does Excel know to use to open the file? You can only rely entirely on the default OS. However, if you encounter BIG5 in traditional Chinese style, garbled characters will still occur.

Finally, use phpMyAdmin and HTMLExcel.

  1. Xmlns: x = "urn: schemas-microsoft-com: office: excel"
  2. Xmlns = "http://www.w3.org/TR/REC-html40">
  3. 1234 Robbin will spit
    5678 Javaeye website

In this way, you can directly echo, and do not need iconv transcoding, as long as you set the Content-type in HTML (here using the UTF-8), of course, the header still needs to add:

  1. Header ("Content-type: application/vnd. ms-excel ");
  2. Header ("Content-Disposition: attachment?filename=export_data.xls ");

This is the case. if you are interested, take a quick test and check whether there are no garbled characters in the exported Chinese content excel ?!

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.