Skip to content

Commit

Permalink
Fix to allow calculate formula against a workbook, without passing in…
Browse files Browse the repository at this point in the history
… a cell
  • Loading branch information
MarkBaker committed Sep 17, 2015
1 parent f6a2107 commit 49d123e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Classes/PHPExcel/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2720,19 +2720,27 @@ public function calculateFormula($formula, $cellID = null, PHPExcel_Cell $pCell
$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));
} catch (PHPExcel_Exception $e) {
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;
}
Expand Down

0 comments on commit 49d123e

Please sign in to comment.