When you first retrieve a calculated value with a call to getCalculatedValue()
, PHPExcel (by default) caches the result, so subsequent calls won't recalculate, but simply return the cached value.
This reduces the calculation overhead typically found when the same calculated cell is referenced in other cell formulae
It can be a problem when you're reading calculated data, then changing cell values and then re-calculating, so PHPExcel provides methods that allow you to control the cache
You can change the default behaviour so that calculated results are never cached, by disabling the calculation cache using either:
PHPExcel_Calculation::getInstance($objPHPExcel)->disableCalculationCache();
or:
PHPExcel_Calculation::getInstance($objPHPExcel)->setCalculationCacheEnabled(false);
Or you can flush the cache at any point by making a call to:
PHPExcel_Calculation::getInstance($objPHPExcel)->clearCalculationCache();
Note that the getOldCalculatedValue()
method is used to retrieve the last value calculated for a cell by MS Excel itself, not from within PHPExcel. It isn't guaranteed to reflect the current data in any way, because it's possible to disable MS Excel from executing formula calculations; but can sometimes be useful for formulae that reference external files or data sources.