Solve 2 problems:
1. Text data such as identity cards are automatically converted to scientific notation.
2. The problem of Chinese garbled characters
How Excel exports from a Web page. When we send this data to the client, we want to have the client program (the browser) read it in Excel format, so we set the MIME type to: application/ Vnd.ms-excel, when Excel reads a file, it renders the data in the format of each cell, and if the cell does not have a specified format, Excel renders the cell's data in the default format. This gives us the space to customize the data format, and of course we must use the format supported by Excel. Here's a list of some commonly used formats:
1) Text: vnd.ms-excel.numberformat:@
2) Date: VND.MS-EXCEL.NUMBERFORMAT:YYYY/MM/DD
3) Number: vnd.ms-excel.numberformat:#,# #0.00
4) Currency: vnd.ms-excel.numberformat:¥#,# #0.00
5) Percentage: Vnd.ms-excel.numberformat: #0.0%
These formats you can also customize, such as the year you can be defined as: yy-mm and so on. So what do you know about these formats and how do you add them to the cell? Very simply, we just need to add the style to the corresponding label pair (that is, the closing tag). For example, add a style to the label pair, as follows: 410522198402161833
Similarly, we can also add style, can also give </tr>
Add a style; When we add a style to both the parent tag pair and the child label pair, which style will the data be rendered? After testing, it is rendered in a style that is closest to the data.
For example, the style of the ID column:
Echo "". $printable. " \ n ";
copy code code is as follows:
$filename =iconv (" UTF-8 "," Gb2312//ignore "," member name. xls ");//date (' y-m-d-h-i-s ').". XLS ";
Header ("Content-type:application/vnd.ms-excel");
Header ("accept-ranges:bytes");
Header ("Content-disposition:attachment;filename=". $filename);//$filename exported file name
Header ("Pragma:no-cache" );
Header ("expires:0");
Echo ' xmlns:x= "Urn:schemas-microsoft-com:office:excel"
xmlns= "HTTP://WWW.W3.ORG/TR/REC-HTML40" >
';
echo "
". Iconv (" UTF-8 "," Gb2312//ignore "," member name ")." | "
. Iconv (" UTF-8 "," Gb2312//ignore "," Account ")." |
". Iconv (" UTF-8 "," Gb2312//ignore "," Contacts ")." |
"; foreach ($list as $v) {echo '
"; echo "
". Iconv (" UTF-8 "," Gb2312//ignore ", $v [" user_name "])." | "; echo "
". $v [" account_id "]." | "; echo "
". Iconv (" UTF-8 "," Gb2312//ignore ", $v [" Contact_Name "])." | "; echo "
"; } echo "
";
http://www.bkjia.com/PHPjc/740219.html www.bkjia.com true http://www.bkjia.com/PHPjc/740219.html techarticle Solve 2 problems: 1. Text data such as ID cards are automatically converted to scientific notation. 2. The problem of Chinese garbled excel the principle of exporting from a Web page. When we put these data ...