From 49d123e910b12ecdab66b23700aed513124371f3 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 17 Sep 2015 23:56:41 +0100 Subject: [PATCH] Fix to allow calculate formula against a workbook, without passing in a cell --- Classes/PHPExcel/Calculation.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Classes/PHPExcel/Calculation.php b/Classes/PHPExcel/Calculation.php index 307db19..809c571 100644 --- a/Classes/PHPExcel/Calculation.php +++ b/Classes/PHPExcel/Calculation.php @@ -2720,10 +2720,16 @@ class PHPExcel_Calculation $this->_debugLog->clearLog(); $this->cyclicReferenceStack->clear(); - // Disable calculation cacheing because it only applies to cell calculations, not straight formulae - // But don't actually flush any cache - $resetCache = $this->getCalculationCacheEnabled(); - $this->calculationCacheEnabled = false; + if ($this->workbook !== null && $cellID === null && $pCell === null) { + $cellID = 'A1'; + $pCell = $this->workbook->getActiveSheet()->getCell($cellID); + } else { + // Disable calculation cacheing because it only applies to cell calculations, not straight formulae + // But don't actually flush any cache + $resetCache = $this->getCalculationCacheEnabled(); + $this->calculationCacheEnabled = false; + } + // Execute the calculation try { $result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell)); @@ -2731,8 +2737,10 @@ class PHPExcel_Calculation throw new PHPExcel_Calculation_Exception($e->getMessage()); } - // Reset calculation cacheing to its previous state - $this->calculationCacheEnabled = $resetCache; + if ($this->workbook === null) { + // Reset calculation cacheing to its previous state + $this->calculationCacheEnabled = $resetCache; + } return $result; }