/** * Calculate the value of a formula * * @param string $formula Formula to parse * @return mixed * @throws Exception */ public function calculateFormula($formula, $cellID = null, PHPExcel_Cell $pCell = null) { // Initialise the logging settings $this->formulaError = null; $this->debugLog = $this->debugLogStack = array(); // Disable calculation cacheing because it only applies to cell calculations, not straight formulae // But don't actually flush any cache $resetCache = $this->getCalculationCacheEnabled(); self::$_calculationCacheEnabled = false; // Execute the calculation try { $result = self::_unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell)); } catch (Exception $e) { throw new Exception($e->getMessage()); } // Reset calculation cacheing to its previous state self::$_calculationCacheEnabled = $resetCache; return $result; }