I have got a problem with PHPExcel as below function
function Test($a, $b) {
// Create a new PHPExcel object with a single sheet
$objPHPExcel = new PHPExcel();
$activeSheet = $objPHPExcel->getActiveSheet();
$activeSheet->SetCellValue('B2',$a);
$activeSheet->SetCellValue('B3',$b);
$activeSheet->SetCellValue('C4',"=B2+B3");
$C4 = $activeSheet ->getCell('C4')->getCalculatedValue();
echo "C4:$C4<br/>";
}
Finally, I call this function
Test(10, 20);
Test(40, 70);
Test(30, 80);
but, result is
C4:30
C4:30
C4:30
Why getCalculatedValue() DOESN’T change result? It seems like this function only gets the first value.
You can change the result, but for performance reasons the calculation engine caches the result of a formula calculation once it’s been calculated. If you want to change the underlying data, you have to flush that cache before requesting the calculated value again:
or
You can also change this default behaviour – so that results are not cached at all – before issuing any other requests to the calculation engine: