Mysql-php export excel data, ID card output problems

Source: Internet
Author: User
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 ..?

  1. Put single quotation marks before:$objPHPExcel->getActiveSheet()->setCellValue('A1', "'". 123456789033);

  2. 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,xlsOrxlsx, 1 and 3, the generation is relatively good for processing,csvBy separator, but it is difficult to process strings,xlsxIt's xml (it seems you have encapsulated it for processing ),xlsxThe 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 usePHPExcelUse it directly.Composer requireNow, 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);

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.