PHPExcel保存错误-单元格坐标字符串不能是单元格区域

PHPExcel save error - Cell coordinate string can not be a range of cells

我目前正在尝试保存用 PHPExcel 加载的 excel 文件。模板文件有多个 sheet 引用公式中的其他 sheet。该模板是从我的本地 Apache 服务器加载的。加载文件后,我尝试保存它,但它抛出异常 "Cell coordinate string can not be a range of cells"。使用 HTML writer 完美显示。

这是我的代码:

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";
}

我希望我的模板 sheet 可以像往常一样在 PHPExcel 中下载,但无法解决此问题。还有其他人 运行 喜欢类似的东西吗?

下载的文档是完全空白的,除了打印的异常 "Caught exception: Cell coordinate string can not be a range of cells".

PHP 输出中有什么?

你的某个地方有错误数据。三种情况抛出该异常:

  1. 尝试查找绝对坐标时会传递一个包含“:”或“,”的字符串

  1. 尝试查找 absoluteReference 时传递了一个包含“:”或“,”的字符串

  1. coordinateFromString 在字符串变量中用“:”或“,”调用。

我会寻找不应该出现在 PHP 输出或模板文件中的单元格中的逗号或全冒号...

对于将来遇到此异常的任何人:

从您的文档中删除格式并尝试使用 PHPExcel 保存它。 我不确定确切的来源,但删除后我用 Google Sheets 复制了格式,并且作者完美地导出了。