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.
Transfer from http://blog.163.com/tfz_0611_go/blog/static/20849708420146172398214/
Phpexcel long Digital string display for scientific counting