Home > Backend Development > PHP Tutorial > How to export data from php to excel to prevent digital character formats such as ID cards from becoming scientific notation

How to export data from php to excel to prevent digital character formats such as ID cards from becoming scientific notation

WBOY
Release: 2016-07-29 08:55:51
Original
1999 people have browsed it

PHP Generally, phpexcel is used to export excel;

I usually use this method:

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=logs.xls" );
下面写原生态的table即可
Copy after login

But exporting the ID number in this way will become scientific notation;

The solution is:

Let’s learn about excel from the web The principle of export on the page. When we send this data to the client, we want the client program (browser) to read it in excel format, so set the mime type to: application/vnd.ms-excel, when excel reads the file The data will be presented in the format of each cell. If the cell does not have a specified format, Excel will present the data of the cell in the default format. This provides us with space to customize the data format. Of course, we must use the format supported by excel. Here are 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.00%
You can also use these formats Customized, for example, you can define the year and month as: yy-mm, etc. So knowing these formats, how to add these formats to the cell? It's very simple, we just need to add the style to the corresponding tag pair (that is, the closing tag). For example, , add a style to the label pair as follows: 410522198402161833Similarly, we can also add styles to

, we can also add styles to < /tr>,
; when we add styles to the parent tag When styles are added to both pairs and sub-tag pairs, which style will the data be presented in? After testing, it will be presented in the style closest to the data.
"
So I set the style of the corresponding ID card column when exporting data according to the method he said:
echo "".$printable ."n";
It really worked, and I didn’t waste a long time checking the information.

The above introduces the method of exporting data from PHP to excel to prevent the format of digital characters such as ID cards from changing into scientific notation, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template