我有一个包含公式的 Excel 电子表格。我想知道使用公式并根据给定输入计算输出的最佳方法是什么。
我的第一个倾向是将展开加载到 PHPExcel 对象中,并将公式中涉及的每个单元格的值设置为给定的输入,然后最终读取结果。
编辑:我尝试使用以下方法获取公式的计算值:
getCalculatedValue()
我在应该包含“原样”传播的计算值的单元格上运行此方法,但它会吐出 Excel5.php 和 MathTrig.php 的未定义偏移错误以及不正确的结果:
Notice: Undefined offset: 437 in /Applications/MAMP/htdocs/bang/Classes/PHPExcel/Reader/Excel5.php on line 5679
Notice: Undefined offset: 438 in /Applications/MAMP/htdocs/bang/Classes/PHPExcel/Reader/Excel5.php on line 5679
Notice: Undefined offset: 439 in /Applications/MAMP/htdocs/bang/Classes/PHPExcel/Reader/Excel5.php on line 5679
Notice: Undefined offset: 9 in /Applications/MAMP/htdocs/bang/Classes/PHPExcel/Calculation/MathTrig.php on line 1171
PHPExcel中调试的公式和堆栈跟踪是:
Value is =SUMIF(Sheet3!A1:H530,"=212410000",Sheet3!H1:H530)
Parser Stack :-
Array
(
[0] => Array
(
[type] => Cell Reference
[value] => Sheet3!A1
[reference] => Sheet3!A1
)
[1] => Array
(
[type] => Cell Reference
[value] => Sheet3!H530
[reference] => Sheet3!H530
)
[2] => Array
(
[type] => Binary Operator
[value] => :
[reference] =>
)
[3] => Array
(
[type] => Value
[value] => "=212410000"
[reference] =>
)
[4] => Array
(
[type] => Cell Reference
[value] => Sheet3!H1
[reference] => Sheet3!H1
)
[5] => Array
(
[type] => Cell Reference
[value] => Sheet3!H530
[reference] => Sheet3!H530
)
[6] => Array
(
[type] => Binary Operator
[value] => :
[reference] =>
)
[7] => Array
(
[type] => Operand Count for Function SUMIF()
[value] => 3
[reference] =>
)
[8] => Array
(
[type] => Function
[value] => SUMIF(
[reference] =>
)
)
Excel5.php 中触发错误的行是:
// offset: 1; size: 2; one-based index to definedname record
$definedNameIndex = self::_GetInt2d($formulaData, 1) - 1;
// offset: 2; size: 2; not used
$data = $this->_definedname[$definedNameIndex]['name']; // errors here