When I was doing a PHP project recently, I encountered a problem.
Function: Export data using Phpexcel.
Problem Description: Four digits after export ID is 0000
This is because in Excel, if you enter or copy an extra long number string in a default grid, it is displayed as a scientific method of calculation.
Method One: Set cell as Text
$objPHPExcel = new Phpexcel ();
$objPHPExcel->setactivesheetindex (0);
$objPHPExcel->getactivesheet ()->settitle (' simple ');
Set A3 cell to text
$objPHPExcel->getactivesheet ()->getstyle (' A3 ')->getnumberformat ()->
Setformatcode (phpexcel_style_numberformat::format_text);
You can also set the entire row or column of Style/
*
//e as text
$objPHPExcel->getactivesheet ()->getstyle (' E ')-> Getnumberformat ()
->setformatcode (phpexcel_style_numberformat::format_text);
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 settings for long numeric strings or text to display the results of scientific notation.
Method Two: The specified data type that is displayed when the value is set
$objPHPExcel = new Phpexcel ();
$objPHPExcel->setactivesheetindex (0);
$objPHPExcel->getactivesheet ()->settitle (' simple ');
$objPHPExcel->getactivesheet ()->setcellvalueexplicit (' D1 ', 123456789033, Phpexcel_cell_datatype::type_ STRING);
Method Three: 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 use of the second to third, the first one does not fundamentally solve the problem.