Move calculator token stack class into its own file
This commit is contained in:
parent
a62b133540
commit
3f981d84d4
|
@ -2663,7 +2663,7 @@ class PHPExcel_Calculation {
|
||||||
|
|
||||||
// Start with initialisation
|
// Start with initialisation
|
||||||
$index = 0;
|
$index = 0;
|
||||||
$stack = new PHPExcel_Token_Stack;
|
$stack = new PHPExcel_Calculation_Token_Stack;
|
||||||
$output = array();
|
$output = array();
|
||||||
$expectingOperator = false; // We use this test in syntax-checking the expression to determine when a
|
$expectingOperator = false; // We use this test in syntax-checking the expression to determine when a
|
||||||
// - is a negation or + is a positive operator rather than an operation
|
// - is a negation or + is a positive operator rather than an operation
|
||||||
|
@ -3007,7 +3007,7 @@ class PHPExcel_Calculation {
|
||||||
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
|
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
|
||||||
// so we store the parent worksheet so that we can re-attach it when necessary
|
// so we store the parent worksheet so that we can re-attach it when necessary
|
||||||
$pCellParent = ($pCell !== NULL) ? $pCell->getParent() : null;
|
$pCellParent = ($pCell !== NULL) ? $pCell->getParent() : null;
|
||||||
$stack = new PHPExcel_Token_Stack;
|
$stack = new PHPExcel_Calculation_Token_Stack;
|
||||||
|
|
||||||
// Loop through each token in turn
|
// Loop through each token in turn
|
||||||
foreach ($tokens as $tokenData) {
|
foreach ($tokens as $tokenData) {
|
||||||
|
@ -3085,12 +3085,7 @@ class PHPExcel_Calculation {
|
||||||
}
|
}
|
||||||
$cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow);
|
$cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow);
|
||||||
if ($pCellParent !== NULL) {
|
if ($pCellParent !== NULL) {
|
||||||
$referencedWorksheet = $pCellParent->getParent()->getSheetByName($sheet1);
|
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($sheet1), false);
|
||||||
if ($referencedWorksheet) {
|
|
||||||
$cellValue = $this->extractCellRange($cellRef, $referencedWorksheet, false);
|
|
||||||
} else {
|
|
||||||
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
||||||
}
|
}
|
||||||
|
@ -3210,15 +3205,10 @@ class PHPExcel_Calculation {
|
||||||
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
|
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
|
||||||
$this->_writeDebug('Evaluating Cell Range '.$cellRef.' in worksheet '.$matches[2]);
|
$this->_writeDebug('Evaluating Cell Range '.$cellRef.' in worksheet '.$matches[2]);
|
||||||
if ($pCellParent !== NULL) {
|
if ($pCellParent !== NULL) {
|
||||||
$referencedWorksheet = $pCellParent->getParent()->getSheetByName($matches[2]);
|
|
||||||
if ($referencedWorksheet) {
|
|
||||||
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
|
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
|
||||||
} else {
|
} else {
|
||||||
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
|
||||||
}
|
|
||||||
$this->_writeDebug('Evaluation Result for cells '.$cellRef.' in worksheet '.$matches[2].' is '.$this->_showTypeDetails($cellValue));
|
$this->_writeDebug('Evaluation Result for cells '.$cellRef.' in worksheet '.$matches[2].' is '.$this->_showTypeDetails($cellValue));
|
||||||
// $cellRef = $matches[2].'!'.$cellRef;
|
// $cellRef = $matches[2].'!'.$cellRef;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3248,12 +3238,11 @@ class PHPExcel_Calculation {
|
||||||
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
|
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
|
||||||
$this->_writeDebug('Evaluating Cell '.$cellRef.' in worksheet '.$matches[2]);
|
$this->_writeDebug('Evaluating Cell '.$cellRef.' in worksheet '.$matches[2]);
|
||||||
if ($pCellParent !== NULL) {
|
if ($pCellParent !== NULL) {
|
||||||
$referencedWorksheet = $pCellParent->getParent()->getSheetByName($matches[2]);
|
if ($pCellParent->getParent()->getSheetByName($matches[2])->cellExists($cellRef)) {
|
||||||
if (($referencedWorksheet) && ($referencedWorksheet->cellExists($cellRef))) {
|
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
|
||||||
$cellValue = $this->extractCellRange($cellRef, $referencedWorksheet, false);
|
|
||||||
$pCell->attach($pCellParent);
|
$pCell->attach($pCellParent);
|
||||||
} else {
|
} else {
|
||||||
$cellValue = NULL;
|
$cellValue = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
return $this->_raiseFormulaError('Unable to access Cell Reference');
|
||||||
|
@ -3642,7 +3631,7 @@ class PHPExcel_Calculation {
|
||||||
if (!isset($aReferences[1])) {
|
if (!isset($aReferences[1])) {
|
||||||
// Single cell in range
|
// Single cell in range
|
||||||
list($currentCol,$currentRow) = sscanf($aReferences[0],'%[A-Z]%d');
|
list($currentCol,$currentRow) = sscanf($aReferences[0],'%[A-Z]%d');
|
||||||
if ($pSheet && $pSheet->cellExists($aReferences[0])) {
|
if ($pSheet->cellExists($aReferences[0])) {
|
||||||
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
|
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
|
||||||
} else {
|
} else {
|
||||||
$returnValue[$currentRow][$currentCol] = null;
|
$returnValue[$currentRow][$currentCol] = null;
|
||||||
|
@ -3653,7 +3642,7 @@ class PHPExcel_Calculation {
|
||||||
// Extract range
|
// Extract range
|
||||||
list($currentCol,$currentRow) = sscanf($reference,'%[A-Z]%d');
|
list($currentCol,$currentRow) = sscanf($reference,'%[A-Z]%d');
|
||||||
|
|
||||||
if ($pSheet && $pSheet->cellExists($reference)) {
|
if ($pSheet->cellExists($reference)) {
|
||||||
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
|
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
|
||||||
} else {
|
} else {
|
||||||
$returnValue[$currentRow][$currentCol] = null;
|
$returnValue[$currentRow][$currentCol] = null;
|
||||||
|
@ -3820,52 +3809,3 @@ class PHPExcel_Calculation {
|
||||||
|
|
||||||
} // class PHPExcel_Calculation
|
} // class PHPExcel_Calculation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// for internal use
|
|
||||||
class PHPExcel_Token_Stack {
|
|
||||||
|
|
||||||
private $_stack = array();
|
|
||||||
private $_count = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public function count() {
|
|
||||||
return $this->_count;
|
|
||||||
} // function count()
|
|
||||||
|
|
||||||
|
|
||||||
public function push($type,$value,$reference=null) {
|
|
||||||
$this->_stack[$this->_count++] = array('type' => $type,
|
|
||||||
'value' => $value,
|
|
||||||
'reference' => $reference
|
|
||||||
);
|
|
||||||
if ($type == 'Function') {
|
|
||||||
$localeFunction = PHPExcel_Calculation::_localeFunc($value);
|
|
||||||
if ($localeFunction != $value) {
|
|
||||||
$this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // function push()
|
|
||||||
|
|
||||||
|
|
||||||
public function pop() {
|
|
||||||
if ($this->_count > 0) {
|
|
||||||
return $this->_stack[--$this->_count];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} // function pop()
|
|
||||||
|
|
||||||
|
|
||||||
public function last($n=1) {
|
|
||||||
if ($this->_count-$n < 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->_stack[$this->_count-$n];
|
|
||||||
} // function last()
|
|
||||||
|
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
}
|
|
||||||
|
|
||||||
} // class PHPExcel_Token_Stack
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPExcel
|
||||||
|
*
|
||||||
|
* Copyright (c) 2006 - 2012 PHPExcel
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PHPExcel
|
||||||
|
* @package PHPExcel_Calculation
|
||||||
|
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version ##VERSION##, ##DATE##
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class PHPExcel_Calculation_Token_Stack {
|
||||||
|
|
||||||
|
private $_stack = array();
|
||||||
|
private $_count = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public function count() {
|
||||||
|
return $this->_count;
|
||||||
|
} // function count()
|
||||||
|
|
||||||
|
|
||||||
|
public function push($type,$value,$reference=null) {
|
||||||
|
$this->_stack[$this->_count++] = array('type' => $type,
|
||||||
|
'value' => $value,
|
||||||
|
'reference' => $reference
|
||||||
|
);
|
||||||
|
if ($type == 'Function') {
|
||||||
|
$localeFunction = PHPExcel_Calculation::_localeFunc($value);
|
||||||
|
if ($localeFunction != $value) {
|
||||||
|
$this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // function push()
|
||||||
|
|
||||||
|
|
||||||
|
public function pop() {
|
||||||
|
if ($this->_count > 0) {
|
||||||
|
return $this->_stack[--$this->_count];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} // function pop()
|
||||||
|
|
||||||
|
|
||||||
|
public function last($n=1) {
|
||||||
|
if ($this->_count-$n < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $this->_stack[$this->_count-$n];
|
||||||
|
} // function last()
|
||||||
|
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
}
|
||||||
|
|
||||||
|
} // class PHPExcel_Calculation_Token_Stack
|
Loading…
Reference in New Issue