Home > Article > Backend Development > How to export data from php to excel to prevent digital character formats such as ID cards from becoming scientific notation
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即可
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,
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.