Phpexcel four-bit 0000 solution after exporting data IDs

Source: Internet
Author: User
Tags numeric


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.

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.