Home > Backend Development > PHP Tutorial > Long numbers exported by PHPExcel are solved by scientific notation conversion and missing data

Long numbers exported by PHPExcel are solved by scientific notation conversion and missing data

WBOY
Release: 2016-08-08 09:19:16
Original
2399 people have browsed it

The F column of the EXCEL table is a long number, such as 2015072708542427700014133717. After exporting, it will become 201507270854242770001410000. Search the Internet for solutions. The first solution is to set the F column in string form, as follows

$objPHPExcel = new PHPExcel() ;

//Set column F (order number) to text format
$objPHPExcel->getActiveSheet()->getStyle('F')->getNumberFormat()
->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT);
$i=1;
foreach($info as $row){
$asc2 = 65;
foreach($row as $field){
$ objPHPExcel->setActiveSheetIndex(0)->setCellValue(chr($asc2++).$i, $field);
}
$i++;

}The result failed, maybe setting the format something went wrong.

Then continue searching and find the second way

// operate the first worksheet
$objPHPExcel->setActiveSheetIndex(0);
$i=1;
foreach($ info as $row){
$asc2 = 65;
foreach($row as $field){
$objPHPExcel->getActiveSheet()->setCellValueExplicit(chr($asc2++).$ i, $field, PHPExcel_Cell_DataType::TYPE_STRING);
}
$i++;
}Specify the type of this data when setting the cell, and it will be successful.

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the solution to the problem of missing data when long numbers exported by PHPExcel are converted into scientific notation, including aspects of the problem. I hope it will be helpful to friends who are interested in PHP tutorials.

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