Solve Phpexcel long digital string display for scientific counting
In Excel, if you enter or copy an extra-long numeric string in a default grid, it appears as a scientific calculation, such as a social security number, and the workaround is to format the table text or add a single quotation mark before the input.
Using Phpexcel to generate Excel, you will also encounter the same problem, there are three ways to solve it:
1. Set cell to Text
$objPHPExcel = new Phpexcel (); $objPHPExcel->setactivesheetindex (0); $objPHPExcel->getactivesheet () Settitle (' simple ');//Set A3 cell as Text $objphpexcel->getactivesheet ()->getstyle (' A3 ')->getnumberformat () Setformatcode (Phpexcel_style_numberformat::format_text);//You can also set the style/*//e column as text for the entire row or columns $objphpexcel-> Getactivesheet ()->getstyle (' E ')->getnumberformat ()->setformatcode (Phpexcel_style_numberformat::format _TEXT);//The third act text $objphpexcel->getactivesheet ()->getstyle (' 3 ')->getnumberformat ()->setformatcode ( PHPEXCEL_STYLE_NUMBERFORMAT::FORMAT_TEXT); * *
More formats can be found in the phpexcel/style/numberformat.php. Note: The above setting shows the result of scientific notation for long numeric strings or text, because of the scientific notation that PHP uses when dealing with large numbers.
2. Specify the type of data to display when setting the value
$objPHPExcel = new Phpexcel (); $objPHPExcel->setactivesheetindex (0); $objPHPExcel->getactivesheet () Settitle (' simple '); $objPHPExcel->getactivesheet ()->setcellvalueexplicit (' D1 ', 123456789033, phpexcel_cell_datatype::type_string);
3. Add a space before the numeric string to make it a string
$objPHPExcel = new Phpexcel (); $objPHPExcel->setactivesheetindex (0); $objPHPExcel->getactivesheet () Settitle (' simple '); $objPHPExcel->getactivesheet ()->setcellvalue (' D1 ', '. 123456789033);
Recommended to use the second to third type, the first one does not solve the problem at all.
=====================================================================================================
The above content is reproduced, personal supplement as follows:
The first method does not work, and now this setting works:
$objPHPExcel->getactivesheet ()->getstyle (' S '. $i)->getnumberformat ()->setformatcode (phpexcel_style_ Numberformat::format_number);
But in this way, if the number is longer than 15 bits, then 15 will become 0 for the following reasons:
The maximum supported numeric data for Excel is 15 bits in length. When the data length is over 15 bits, starting with the 16th bit, the following numbers are all modified by default to 0.
Solve Phpexcel long digital string display for scientific counting [go]