Skip to content

Commit

Permalink
Minor fixes to cyclic references in formulae
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBaker committed Sep 13, 2014
1 parent 01d6f7f commit 37b4d18
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Classes/PHPExcel/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2374,13 +2374,13 @@ public function saveValueToCache($worksheetName, $cellID, $cellValue) {
* @throws PHPExcel_Calculation_Exception
*/
public function _calculateFormulaValue($formula, $cellID=null, PHPExcel_Cell $pCell = null) {
$cellValue = '';
$cellValue = null;

// Basic validation that this is indeed a formula
// We simply return the cell value if not
$formula = trim($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);

$pCellParent = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL;
Expand All @@ -2392,20 +2392,23 @@ public function _calculateFormulaValue($formula, $cellID=null, PHPExcel_Cell $pC

if (($wsTitle{0} !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) {
if ($this->cyclicFormulaCount <= 0) {
$this->_cyclicFormulaCell = '';
return $this->_raiseFormulaError('Cyclic Reference in Formula');
} elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) &&
($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID)) {
$this->_cyclicFormulaCell = '';
return $cellValue;
} elseif ($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID) {
++$this->_cyclicFormulaCount;
if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) {
$this->_cyclicFormulaCell = '';
return $cellValue;
}
} elseif ($this->_cyclicFormulaCell == '') {
$this->_cyclicFormulaCell = $wsTitle.'!'.$cellID;
if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) {
return $cellValue;
}
$this->_cyclicFormulaCell = $wsTitle.'!'.$cellID;
}
}

Expand Down

0 comments on commit 37b4d18

Please sign in to comment.