Using php to export data to an excel file without using the PHPExcel class, I wrote a simple program to generate an excel file, and then input a row of data, but the ID card number is output to the scientific count, there is a solution on the internet. one is to enclose it with quotation marks, which can solve the problem, and the other is www... I used php to export data to an excel file. I did not use the PHPExcel class. I wrote a simple program myself.
Generate an excel file and input one row of data
However, the ID card number is output as a scientific count, and there are solutions on the internet. one is to add quotation marks to solve the problem,
Another http://www.cnblogs.com/jcz120...
But I feel very troublesome. excuse me, are there any other solutions except these two solutions?
Thank you!
Reply content:
I used php to export data to an excel file. I did not use the PHPExcel class. I wrote a simple program myself.
Generate an excel file and input one row of data
However, the ID card number is output as a scientific count, and there are solutions on the internet. one is to add quotation marks to solve the problem,
Another http://www.cnblogs.com/jcz120...
But I feel very troublesome. excuse me, are there any other solutions except these two solutions?
Thank you!
Append a space to the ID card number, which is actually to convert the number into a string.
Add a single quotation mark (single quotation mark in English input) to the front of the ID card number, for example, '2017 .....
You can either add a single quotation mark or change the cell format to text format in advance. These two are the simplest solutions. is it still troublesome ..?
Put single quotation marks before:$objPHPExcel->getActiveSheet()->setCellValue('A1', "'". 123456789033);
Data type:$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1',123456789033, PHPExcel_Cell_DataType::TYPE_STRING);
It is very simple. once I met it, I added "431226198910135411". "\ t" to the end to completely solve the problem. If your problem is solved, please remember the public account phpgod.
++ Updated the split line at 11:18:09, December 9 ,.
The editor of segmentfault really disgusted me. the above t actually escaped me, thanks!
What format of excel file are you generating,csv
,xls
Orxlsx
, 1 and 3, the generation is relatively good for processing,csv
By separator, but it is difficult to process strings,xlsx
It's xml (it seems you have encapsulated it for processing ),xlsx
The format contains the xml for storing strings. you need to store the strings in this xml, and then retrieve the strings according to their serial numbers (this design can reduce the resource occupation of repeated strings ). But still usePHPExcel
Use it directly.Composer require
Now, I have written a library for reading and generating excel files. if it is difficult to maintain compatibility in the future, I can use it directly.PHPExcel
. After all, many traps have been entered.
In addition, the PHPExcel method for processing strings is mentioned above.
Copy upstairs:
$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1',123456789033, PHPExcel_Cell_DataType::TYPE_STRING);