Phpexcel How to format a column as a numeric value

Source: Internet
Author: User
Phpexce

A field with a value of 0 in the database, exported to Excel via Phpexcel, becomes blank, can you make it appear as 0? The Phpexcel version is 1.7.9 and the export format is Excel2003. The following code is found on the internet, but has not been tested successfully, but also please have the experience of the friend pointing twos.
Sets the number format for the contents of the cell. /////  If Phpexcel_writer_excel5 is used to generate the content,//It is important to  note that the const variable in the Phpexcel_style_numberformat class defines the  // In various custom formats, other types can be used normally, but when Setformatcode  //Is format_number, the actual effect is not formatted as "0". Need  //Modify the GETXF ($style) method in the source code of the Phpexcel_writer_excel5_format class,  //In the IF ($this->_biff_version = = 0x0500) { (Near line No. 363) Add a  //Line code:   //if ($ifmt = = = ' 0 ') $ifmt = 1;  //Set format to Phpexcel_style_numberformat::format_number, avoid some large numbers  //are displayed using scientific notation, with the following setautosize method allows the contents//of each row to be displayed in its  entirety as the original content.  $objStyleA 5      ->getnumberformat ()      
Format//Set cell number Formatsecho date (' H:i:s '). "Set cell number formats\n"; $objPHPExcel->getactivesheet ()->getstyle (' e4′)->getnumberformat () Setformatcode (phpexcel_style_numberformat::format_currency_eur_simple), $objPHPExcel->getactivesheet () Duplicatestyle ($objPHPExcel->getactivesheet ()->getstyle (' e4′), ' e5:e13′ ';


Reply to discussion (solution)

How come people have this kind of problem?

An estimate of 0 is null, so it doesn't show up, so you can change the idea to show him as a string
$number = 0;
Echo '. $number

  • 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.