我正在使用 phpexcel 创建一个 xlsx 文件。我在文件中有很多公式。下载文件后,某些公式单元格(并非全部)显示为空白,直到我单击“启用编辑”选项。
我正在使用以下代码:
$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');
这里的问题发生在使用没有启用编辑选项的早期 Office 版本的用户身上。对他们来说,这些单元格显示为空白。
最佳答案
我在其他地方看到了这个答案。如果其他人正在寻找答案。
$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);
关于PHP Excel 在单击启用编辑之前为公式单元格提供空白输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33338593/