Minor fixes to cyclic references in formulae

This commit is contained in:
MarkBaker 2014-09-13 16:12:45 +01:00
parent 01d6f7f1d5
commit 37b4d18d45
1 changed files with 6 additions and 3 deletions

View File

@ -2374,13 +2374,13 @@ class PHPExcel_Calculation {
* @throws PHPExcel_Calculation_Exception * @throws PHPExcel_Calculation_Exception
*/ */
public function _calculateFormulaValue($formula, $cellID=null, PHPExcel_Cell $pCell = null) { public function _calculateFormulaValue($formula, $cellID=null, PHPExcel_Cell $pCell = null) {
$cellValue = ''; $cellValue = null;
// Basic validation that this is indeed a formula // Basic validation that this is indeed a formula
// We simply return the cell value if not // We simply return the cell value if not
$formula = trim($formula); $formula = trim($formula);
if ($formula{0} != '=') return self::_wrapResult($formula); if ($formula{0} != '=') return self::_wrapResult($formula);
$formula = ltrim(substr($formula,1)); $formula = ltrim(substr($formula, 1));
if (!isset($formula{0})) return self::_wrapResult($formula); if (!isset($formula{0})) return self::_wrapResult($formula);
$pCellParent = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL; $pCellParent = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL;
@ -2392,20 +2392,23 @@ class PHPExcel_Calculation {
if (($wsTitle{0} !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) { if (($wsTitle{0} !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) {
if ($this->cyclicFormulaCount <= 0) { if ($this->cyclicFormulaCount <= 0) {
$this->_cyclicFormulaCell = '';
return $this->_raiseFormulaError('Cyclic Reference in Formula'); return $this->_raiseFormulaError('Cyclic Reference in Formula');
} elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) && } elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) &&
($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID)) { ($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID)) {
$this->_cyclicFormulaCell = '';
return $cellValue; return $cellValue;
} elseif ($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID) { } elseif ($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID) {
++$this->_cyclicFormulaCount; ++$this->_cyclicFormulaCount;
if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) { if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) {
$this->_cyclicFormulaCell = '';
return $cellValue; return $cellValue;
} }
} elseif ($this->_cyclicFormulaCell == '') { } elseif ($this->_cyclicFormulaCell == '') {
$this->_cyclicFormulaCell = $wsTitle.'!'.$cellID;
if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) { if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) {
return $cellValue; return $cellValue;
} }
$this->_cyclicFormulaCell = $wsTitle.'!'.$cellID;
} }
} }