PHP export Excel Format data problem _php Tutorial

Source: Internet
Author: User
Tags closing tag
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 "














" "; foreach ($list as $v) {echo ' "; echo " "; echo " "; echo " "; echo " "; } echo "
". Iconv (" UTF-8 "," Gb2312//ignore "," member name ").". Iconv (" UTF-8 "," Gb2312//ignore "," Account ")." ". Iconv (" UTF-8 "," Gb2312//ignore "," Contacts ")."
". Iconv (" UTF-8 "," Gb2312//ignore ", $v [" user_name "])."". $v [" account_id "]."". Iconv (" UTF-8 "," Gb2312//ignore ", $v [" Contact_Name "])."
";

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 ...

  • 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.