harshshahi wrote:
This however does not, I think it is a bug, since the style is showing correctly in Excel (Text), but the leading zero is gone:
$objPHPExcel->setActiveSheetIndex(0)->getDefaultStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
$objPHPExcel->setActiveSheetIndex(0)->fromArray($Users);
I also tried using like: $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '0123Hello'); in combination with the FORMAT_TEXT above - the 0 is gone...
I have included AdvancedValueBinder.phpThank you! I was running out of ideas, I have an array of usernames, many of which include a leading zero, and I could find no way to make it work, your tip of using setValueExplicit with the TYPE_STRING works!
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() ); in my code and it is working fine for all :)
except number format like 23,222.
I have included below code in AdvancedValueBinder.php .But still it is showing error ico with salary.
// Style logic - NumbersPlease look into itif ($dataType === PHPExcel_Cell_DataType::TYPE_NUMERIC) { // Leading zeroes? if (preg_match('/^\d+,\d+$/', $value)) { // Convert value to string $cell->setValueExplicit( $value, PHPExcel_Cell_DataType::TYPE_STRING); // Set style $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1 ); return true; } }
This however does not, I think it is a bug, since the style is showing correctly in Excel (Text), but the leading zero is gone:
$objPHPExcel->setActiveSheetIndex(0)->getDefaultStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
$objPHPExcel->setActiveSheetIndex(0)->fromArray($Users);
I also tried using like: $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '0123Hello'); in combination with the FORMAT_TEXT above - the 0 is gone...