This article provides a detailed analysis of the solution to the Excel garbled File Export in PHP. For more information, see
This article provides a detailed analysis of the solution to the Excel garbled File Export in PHP. For more information, see
In my PHP project, I want to export data to Excel and contain Chinese characters.
I 'd like to know about PHPExcel on the Internet, but this framework is too complicated for my needs. So I still want to find a simple method.
It is actually the easiest way to write data on the Internet, but the problem is that the Chinese encoding is not reliable ..
The Code is as follows:
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment?filename=export_data.xls ");
Echo "name". "\ t ";
Echo "traditional". "\ t ";
Echo "blog". "\ t ";
Echo "\ n ";
Echo "jason". "\ t ";
Echo "@". "\ t ";
Echo "javaeye". "\ t ";
?>
Some students think of adding headers to character sets.
The Code is as follows:
Header ("Content-type: application/vnd. ms-excel; charsets = UTF-8 ");
Question: I only want to tell the browser which character set to choose to view. In the end, I still need to generate the xls file.
Of course. Some people will think of iconv transcoding.
The Code is as follows:
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, it will still be garbled, so it is still unreliable.
Finally, I use phpMyAdmin. We are familiar with using HTMLExcel and HTML. The format is as follows.
The Code is as follows:
Xmlns: x = "urn: schemas-microsoft-com: office: excel"
Xmlns = "http://www.w3.org/TR/REC-html40">
1234 |
Robbin will spit |
5678 |
Javaeye website |
This can directly echo, without iconv transcoding, as long as you set the Content-type in HTML (here is the use of UTF-8), is there a comfortable feeling? Of course, the header must be added.
The Code is as follows:
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment?filename=export_data.xls ");
I would like to share with you a little bit of experience ..
, Hong Kong Space, Hong Kong Server rental, Hong Kong Server rental