我正在逐个单元地比较两列的值,然后在第3列中写入值,如果有更改,则更改否则不更改。
我能够做到这一点。
但是当我尝试获取配方值时,我的问题就出现了。它为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);
?>
并且在echo中得到输出,这意味着没有改变我猜
0
0
0
0
0
0
0
0
0
0
我提到了enter link description here和enter link description here
可以请任何人告诉我代码中哪里出错了
由于
修改
使用公式调试工具后,输出如下
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"
)