Ask to avoid the problem that the xls file phone number exported by phpexcel and the ID card are displayed in scientific notation!

Source: Internet
Author: User
Ask to avoid the problem that the xls file phone number exported by phpexcel and the ID card are displayed in scientific notation! Phpexcel is used for export in recent projects, which is relatively good, but there are several headaches, that is, when exporting data columns, data of the type 013434342333, 053482371284, and 42221312312312312312213 is automatically displayed in scientific notation. for details, see how to display the complete numerical records. the version I used is 1.7.6. thank you, please let me know!


Reply to discussion (solution)

$objStyleA5    ->getNumberFormat()    ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);

As you said on the first floor, Are You Normal ??
I am using 1.7.6 ..
But there is a small trick to solve it.
When you do not need to be the value of the... character in the column of a number
$ ObjPHPExcel-> getActiveSheet ()-> setCellValueByColumnAndRow (0, $ I, ''. $ rs ['cardn']);

Note: add a space here. excel is processed as a string by default ..

PHP code
$ ObjStyleA5
-> GetNumberFormat ()
-> SetFormatCode (PHPExcel_Style_NumberFormat: FORMAT_NUMBER); I also solve the problem by adding spaces, but it is always uncomfortable to carry spaces. do you have any good methods on the second floor ?!
Some articles on the Internet say that some of the source code can be implemented, but the version I use is too high and I cannot find the location where the source code is. if you find a better solution, please kindly advise. thank you !!!

$ ObjPHPExcel-> getActiveSheet ()-> setCellValueByColumnAndRow (0, $ I, $ rs ['cardn'], PHPExcel_Cell_DataType: TYPE_STRING );
Specify the cell type as text. how can this problem be solved?
The previous version seems to have been specified and displayed in scientific notation, so you need to modify the code. The new version should have a specified type.

#include 
 
  void main{printf('%d'&b);}
 

Method 1: add spaces to the front;

Method 2: $ objActSheet-> setCellValueExplicit ('A1', '000000', PHPExcel_Cell_DataType: TYPE_STRING );

Method 3:
$ ObjActSheet-> setCellValue ('A1', '123 ');
$ ObjActSheet-> getStyle ('A1')-> getNumberFormat ()-> setFormatCode (PHPExcel_Style_NumberFormat: FORMAT_NUMBER );

In my practice, it is best to use method 2.

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.