getCalculatedValue(); $obj-6ren">
gpt4 book ai didi

phpExcel:getCalculatedValue() 返回#VALUE

转载 作者:可可西里 更新时间:2023-11-01 12:33:37 30 4
gpt4 key购买 nike

谁能帮我处理 phpExcel 代码:

此代码:

$objPHPExcel->getActiveSheet()->getCell("AF19")->getCalculatedValue();
$objPHPExcel->getActiveSheet()->getCell("AF19")->getFormattedValue();
$objPHPExcel->getActiveSheet()->getCell("AF19")->getValue();

返回:

#VALUE!
#VALUE!
=AE19*I19

提前致谢! :)

最佳答案

为了帮助调试问题,在 DEBUG 模式下运行计算:

function testFormula($sheet,$cell) {
$formulaValue = $sheet->getCell($cell)->getValue();
echo 'Formula Value is' , $formulaValue , PHP_EOL;
$expectedValue = $sheet->getCell($cell)->getOldCalculatedValue();
echo 'Expected Value is ' ,
((!is_null($expectedValue)) ?
$expectedValue :
'UNKNOWN'
) , PHP_EOL;

$calculate = false;
try {
$tokens = PHPExcel_Calculation::getInstance()->parseFormula($formulaValue,$sheet->getCell($cell));
echo 'Parser Stack :-' , PHP_EOL;
print_r($tokens);
echo PHP_EOL;
$calculate = true;
} catch (Exception $e) {
echo 'PARSER ERROR: ' , $e->getMessage() , PHP_EOL;

echo 'Parser Stack :-' , PHP_EOL;
print_r($tokens);
echo PHP_EOL;
}

if ($calculate) {
try {
$cellValue = $sheet->getCell($cell)->getCalculatedValue();
echo 'Calculated Value is ' , $cellValue , PHP_EOL;

echo 'Evaluation Log:' , PHP_EOL;
print_r(PHPExcel_Calculation::getInstance()->debugLog);
echo PHP_EOL;
} catch (Exception $e) {
echo 'CALCULATION ENGINE ERROR: ' , $e->getMessage() , PHP_EOL;

echo 'Evaluation Log:' , PHP_EOL;
print_r(PHPExcel_Calculation::getInstance()->debugLog);
echo PHP_EOL;
}
}
}

$sheet = $objPHPExcel->getActiveSheet();
PHPExcel_Calculation::getInstance()->writeDebugLog = true;

testFormula($sheet,'AF19');

这个输出应该有助于诊断问题

关于phpExcel:getCalculatedValue() 返回#VALUE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16708471/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com