使用 phpexcel 从其他 sheet 读取公式

read formula from other sheet with phpexcel

试图维护一些陈旧的代码,我在 import symfony 命令中遇到了 phpexcel 的问题。

似乎库无法正确计算链接到与活动 sheet 相同文档的另一个 sheet 的公式。

我得到的错误是:

[PHPExcel_Calculation_Exception]
Price Template Map!B2 -> Invalid cell coordinate A

我的代码是:

try {
    $inputFileType = \PHPExcel_IOFactory::identify($filePath);
    $objReader = \PHPExcel_IOFactory::createReader($inputFileType);
    $objReader->setLoadSheetsOnly(array($this->getListName(), 'Template Info'));
    $objReader->setIncludeCharts(true);

    $objPHPExcel  = $objReader->load($filePath);
} catch (\Exception $e) {
    throw new \Exception("Invalid file");
}
$sheet = $objPHPExcel->getActiveSheet();
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();

$fieldsNumber = array();
$filterData = array();
$templateIdList = array();

for ($i = 1; $i <= $highestRow; $i++) {
    $rowData = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, null, true, false);
    $rowData = $rowData[0];
    var_dump($rowData);
}

带headers的第一行读对了,其余的读错了。

我的公式是:

=VLOOKUP(A18,'Template Info'!A:C,3,FALSE)"

如果需要,请随时向我询问更多信息!

提前谢谢大家:) !

使用getCalculatedValue()函数。

问题是列引用:PHPExcel 计算引擎支持范围引用(甚至对其他工作表),但不支持行或列引用

所以

=VLOOKUP(A18,'Template Info'!A1:C100,3,FALSE)

是有效的,但是

=VLOOKUP(A18,'Template Info'!A:C,3,FALSE)

无法计算