Home > Backend Development > PHP Tutorial > mysql - php exports excel data, ID card output problem

mysql - php exports excel data, ID card output problem

WBOY
Release: 2016-10-11 14:23:16
Original
1417 people have browsed it

Use PHP to export data to an excel file. Instead of using the PHPExcel class, I wrote a simple program
Generate the excel file, and then input the data line by line
But the ID number is output in scientific notation. There are solutions online, one is Adding quotation marks in front of it can indeed solve the problem,
Another one is http://www.cnblogs.com/jcz120...
But it feels very troublesome. I would like to ask you, is there no other way besides these two solutions? ?
Thank you everyone

Reply content:

Use PHP to export data to an excel file. Instead of using the PHPExcel class, I wrote a simple program
Generate the excel file, and then input the data line by line
But the ID number is output in scientific notation. There are solutions online, one is Adding quotation marks in front of it can indeed solve the problem,
Another one is http://www.cnblogs.com/jcz120...
But it feels very troublesome. I would like to ask you, is there no other way besides these two solutions? ?
Thank you everyone

Appending a space to the ID number is actually just converting the number into a string

Add a single quote in front of the ID number (single quote in English input state), such as '4400202....

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. Place a single quote in front: $objPHPExcel->getActiveSheet()->setCellValue('A1', "'". 123456789033);

  2. Specify data type: <code>$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1',123456789033, PHPExcel_Cell_DataType::TYPE_STRING);</code>

It's very simple. I've encountered it before. Just add "431226198910135411"."t" at the end and it's completely solved. If your problem is solved, please remember to follow it, WeChat public account: phpgod.
+++Updated dividing line, time: 2016-10-9 11:18:09+++
segmentfault’s editor really disgusted me, the t above was escaped for me, fuck!

What format of excel file are you generating? csv, xls or xlsx. If it is 1 or 3, it is relatively easy to process. csvAccording to the delimiter, but it is difficult to process strings, xlsx It is xml (I feel like you should have encapsulated and processed this). The xlsx format has xml specifically for storing strings. You need to save the string into this xml and then retrieve it according to the serial number of the string (this design is estimated Can reduce resources occupied by repeated strings). But it’s better to use PHPExcel. Just use Composer require. I have also written a library for reading and generating excel before. Later, compatibility is more troublesome, so I just use PHPExcel. After all, others have filled in a lot of holes.

In addition, PHPExcel’s method of processing strings is mentioned above.

Copy upstairs:

<code>$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1',123456789033, PHPExcel_Cell_DataType::TYPE_STRING);</code>
Copy after login
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