I am creating an xlsx file using phpexcel. I have many formulas in the file. when the file is downloaded, some of the formula cells (not all) appear blank until I click the Enable Editing option.
I am using the following code :
$objPHPExcel = new PHPExcel();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$xlsName.'"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
The problem here occurs with users who are using previous Office versions who don't have the enable editing option. For them these cells appear blank.
I came across this answer somewhere else. If anyone else is looking for answers.
$spreadsheet = new \PHPExcel();
$writer = new \PHPExcel_Writer_Excel2007($spreadsheet);
//Do things with the $spreadsheet
//This is the solution, do it before saving
$writer->setPreCalculateFormulas();
$writer->save($saving_filepath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With