Php getCalculatedValue未提供正确的值
我正在逐单元格比较两列的值,然后在第三列中写入值(如果有更改),然后更改,否则不更改 我完全可以做到这一点 但当我试图获取公式化的值时,问题就出现了。它给我Php getCalculatedValue未提供正确的值,php,phpexcel,Php,Phpexcel,我正在逐单元格比较两列的值,然后在第三列中写入值(如果有更改),然后更改,否则不更改 我完全可以做到这一点 但当我试图获取公式化的值时,问题就出现了。它给我0作为所有值的输出 我要获取的代码如下: <?php /** Error reporting */ error_reporting(E_ALL); include 'PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel1 = new PHPExcel(); requir
0
作为所有值的输出
我要获取的代码如下:
<?php
/** Error reporting */
error_reporting(E_ALL);
include 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel1 = new PHPExcel();
require_once 'PHPExcel/IOFactory.php';
$directory = 'C:\Users\user\Desktop\Google-Competitors\\';
$target_file_path = $directory . "domain-page-size.xlsx";
$change_size_url = $directory . "url-list-with-change-in-page-size.xlsx";
$objPHPExcel = PHPExcel_IOFactory::load($target_file_path); //Load file
$objWorksheet = $objPHPExcel->getActiveSheet(); //get active sheet
$highestRow = $objWorksheet->getHighestRow(); //get total rows
$highestColumn = $objWorksheet->getHighestColumn(); //get total columns
$objPHPExcel1 = PHPExcel_IOFactory::load($change_size_url);
$objWorksheet1 = $objPHPExcel1->getActiveSheet();
$highestColumn = $objWorksheet1->getHighestColumn();
$timestamp = date('M Y');
$objPHPExcel1->setActiveSheetIndex(0)->setTitle($timestamp);
$i= 1;
for ($row = 2; $row <= 547; ++$row)
{
$cell = "E".$row;
// $val = $objWorksheet->getCell($cell)->getCalculatedValue();
$val = $objWorksheet->getCell($cell)->getOldCalculatedValue();
echo $val;
if($val=="Change")
{
$url_cell = "B".$row;
$url_val = $objWorksheet->getCell($url_cell);
$strvar = (string) $url_val;
$objPHPExcel1->setActiveSheetIndex()->setCellValue('A'.$i, $strvar);
$i++;
}
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel1, 'Excel2007');
$objWriter->save($change_size_url);
?>
我提到
谁能告诉我我在代码中哪里出错了吗
谢谢
编辑
使用公式调试工具后,我得到如下输出
11:34:13 Create new PHPExcel object
11:34:13 Add some data
11:34:14 Rename worksheet
Formula Value is=IF(ABS(C6-D6)>10,"Change", "No Change")
Expected Value is 0
Parser Stack :-
Array
(
[0] => Array
(
[type] => Cell Reference
[value] => C6
[reference] => C6
)
[1] => Array
(
[type] => Cell Reference
[value] => D6
[reference] => D6
)
[2] => Array
(
[type] => Binary Operator
[value] => -
[reference] =>
)
[3] => Array
(
[type] => Operand Count for Function ABS()
[value] => 1
[reference] =>
)
[4] => Array
(
[type] => Function
[value] => ABS(
[reference] =>
)
[5] => Array
(
[type] => Value
[value] => 10
[reference] =>
)
[6] => Array
(
[type] => Binary Operator
[value] => >
[reference] =>
)
[7] => Array
(
[type] => Value
[value] => "Change"
[reference] =>
)
[8] => Array
(
[type] => Value
[value] => "No Change"
[reference] =>
)
[9] => Array
(
[type] => Operand Count for Function IF()
[value] => 3
[reference] =>
)
[10] => Array
(
[type] => Function
[value] => IF(
[reference] =>
)
)
Calculated Value is No Change
Evaluation Log:
Array
(
[0] => Testing cache value for cell Simple!E6
[1] => Simple!E6 => Evaluating Cell C6 in current worksheet
[2] => Simple!E6 => Evaluation Result for cell Simple!C6 is a floating point number with a value of 34738
[3] => Simple!E6 => Evaluating Cell D6 in current worksheet
[4] => Simple!E6 => Evaluation Result for cell Simple!D6 is a floating point number with a value of 34742
[5] => Simple!E6 => Evaluating 34738 - 34742
[6] => Simple!E6 => Evaluation Result is a floating point number with a value of -4
[7] => Simple!E6 => Evaluating Function ABS() with 1 argument
[8] => Simple!E6 => Evaluating ABS( -4 )
[9] => Simple!E6 => Evaluation Result for ABS() function call is a floating point number with a value of 4
[10] => Simple!E6 => Evaluating 4 > 10
[11] => Simple!E6 => Evaluation Result is a boolean with a value of FALSE
[12] => Simple!E6 => Evaluating Function IF() with 3 arguments
[13] => Simple!E6 => Evaluating IF( FALSE, "Change", "No Change" )
[14] => Simple!E6 => Evaluation Result for IF() function call is a string with a value of "No Change"
)
我重新创建了您上面发布的工作表片段,并使用它测试了PHPExcel,它使用
getCalculatedValue()
正确地计算了所有公式-您可以尝试使用公式调试工具吗,如感谢Mark for Aowesome库中所示。但是我不知道如何调试:(.你能详细解释一下吗?你读了我链接的要点了吗?基本上你只是把你想调试的工作表和单元格地址的细节传递给testFormula()
函数,该函数在gist代码示例中定义,然后它将显示一个输出流,精确显示计算公式所采取的步骤,以及所涉及的值的详细信息和我刚刚实现的每个阶段的结果。我正在问题editI sent中添加输出$cell='E4';
11:34:13 Create new PHPExcel object
11:34:13 Add some data
11:34:14 Rename worksheet
Formula Value is=IF(ABS(C6-D6)>10,"Change", "No Change")
Expected Value is 0
Parser Stack :-
Array
(
[0] => Array
(
[type] => Cell Reference
[value] => C6
[reference] => C6
)
[1] => Array
(
[type] => Cell Reference
[value] => D6
[reference] => D6
)
[2] => Array
(
[type] => Binary Operator
[value] => -
[reference] =>
)
[3] => Array
(
[type] => Operand Count for Function ABS()
[value] => 1
[reference] =>
)
[4] => Array
(
[type] => Function
[value] => ABS(
[reference] =>
)
[5] => Array
(
[type] => Value
[value] => 10
[reference] =>
)
[6] => Array
(
[type] => Binary Operator
[value] => >
[reference] =>
)
[7] => Array
(
[type] => Value
[value] => "Change"
[reference] =>
)
[8] => Array
(
[type] => Value
[value] => "No Change"
[reference] =>
)
[9] => Array
(
[type] => Operand Count for Function IF()
[value] => 3
[reference] =>
)
[10] => Array
(
[type] => Function
[value] => IF(
[reference] =>
)
)
Calculated Value is No Change
Evaluation Log:
Array
(
[0] => Testing cache value for cell Simple!E6
[1] => Simple!E6 => Evaluating Cell C6 in current worksheet
[2] => Simple!E6 => Evaluation Result for cell Simple!C6 is a floating point number with a value of 34738
[3] => Simple!E6 => Evaluating Cell D6 in current worksheet
[4] => Simple!E6 => Evaluation Result for cell Simple!D6 is a floating point number with a value of 34742
[5] => Simple!E6 => Evaluating 34738 - 34742
[6] => Simple!E6 => Evaluation Result is a floating point number with a value of -4
[7] => Simple!E6 => Evaluating Function ABS() with 1 argument
[8] => Simple!E6 => Evaluating ABS( -4 )
[9] => Simple!E6 => Evaluation Result for ABS() function call is a floating point number with a value of 4
[10] => Simple!E6 => Evaluating 4 > 10
[11] => Simple!E6 => Evaluation Result is a boolean with a value of FALSE
[12] => Simple!E6 => Evaluating Function IF() with 3 arguments
[13] => Simple!E6 => Evaluating IF( FALSE, "Change", "No Change" )
[14] => Simple!E6 => Evaluation Result for IF() function call is a string with a value of "No Change"
)