Solve Phpexcel long digital string display for scientific counting [go]

Source: Internet
Author: User

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]

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.