I wish to save my 2 dimensional array into an .xls file. If use this code, the data is saved without leading zeroes:
$arr = array(
array("01", "02", "03"),
array("001", "02", "03"),
array("00001", "02", "03"),
);
// include PHPExcel library
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->fromArray($arr);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save("file.xls");
If use this instead, 01 is saved as 00001:
......
$objPHPExcel->getActiveSheet()->fromArray($arr);
$objPHPExcel->getActiveSheet()->getStyle('A1:C3')->getNumberFormat()->setFormatCode("00000");
.....
How can I solve this problem? How can I save the original data from my array into an .xls file correctly?
strlen()the element and then usestr_repeat()to set the format?