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