我目前正在尝试保存带有phpexcel的Excel文件。模板文件具有多个图纸,可以将其他纸参考公式中。该模板正在从我的本地Apache服务器加载。加载文件后,我尝试保存它,并引发异常"单元格坐标字符串不可能是一系列单元格"。使用HTML作者完美显示。
这是我的代码:
require_once "assets/vendors/PHPExcel/PHPExcel.php";
require_once 'assets/vendors/PHPExcel/PHPExcel/IOFactory.php';
$tmpfname = 'template_files/templateFile.xlsx';
$objReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
$objPHPExcel = $objReader->load($tmpfname);
try {
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "n";
}
我希望我的模板表像往常一样在phpexcel中下载,但无法解决此问题。还有其他人遇到类似的东西吗?
下载的文档完全为空白,并打印了"抓取例外:单元格坐标字符串不可能是一系列单元格"。
对于将来遇到此例外的任何人:
从文档中删除格式,然后尝试使用phpexcel保存。我不确定确切的来源,但是在删除后,我用Google表复制了格式,作者出口得很好。
php输出中有什么?
您在某个地方的数据不好。此例外是在三种情况下抛出的:
- 试图通过一个包含":"或"," 的字符串传递。
或
- 试图通过一个包含":"或"," 的字符串传递。
或
- 在字符串变量中使用":"或"调用坐标。
我会寻找不应该在PHP输出中或模板文件中的单元格中的流浪逗号或完整的逗号...