In PHPExcel, how do I set the format of a column as a numerical value?

Source: Internet
Author: User
In PHPExcel, how do I set the format of a column to a value phpexce?

If the field with a value of 0 in the database is exported to Excel through PHPExcel, how does it become blank? can it be displayed as 0? PHPExcel is 1.7.9 and the export format is Excel2003. The following code is found on the Internet, but it has never been tested successfully. if you have any experience in this field, please give us some advice.
// Set the numeric format of the cell content. //// If PHPExcel_Writer_Excel5 is used to generate content, // note that in the const variable defined in the PHPExcel_Style_NumberFormat class, other types can be used normally, but when setFormatCode // is FORMAT_NUMBER, the actual effect is not set to "0 ". You need to // modify the getXf ($ style) method in the PHPExcel_Writer_Excel5_Format class source code, // in if ($ this-> _ BIFF_version = 0x0500) {(near 363rd rows) first add a // line of code: // if ($ ifmt = '0') $ ifmt = 1; // set the format to PHPExcel_Style_NumberFormat: FORMAT_NUMBER, to prevent some large numbers from being displayed in scientific notation, you can use the setAutoSize method below to display all the content of each row according to the original content. $ ObjStyleA5-> getNumberFormat ()-> setFormatCode (PHPExcel_Style_NumberFormat: FORMAT_NUMBER );
Set the 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 have you ever encountered this problem ,?

It is estimated that 0 is null, so it is not displayed. you can use another method to display it 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.