Minor memory and performance improvements

This commit is contained in:
Mark Baker 2013-01-31 12:13:31 +00:00
parent 0baa487442
commit 9a085abd7d
2 changed files with 65 additions and 116 deletions

View File

@ -114,15 +114,6 @@ class PHPExcel_Calculation {
private static $_calculationCacheEnabled = true; private static $_calculationCacheEnabled = true;
/**
* Calculation cache expiration time
*
* @access private
* @var float
*/
private static $_calculationCacheExpirationTime = 15;
/** /**
* List of operators that can be used within formulae * List of operators that can be used within formulae
* The true/false value indicates whether it is a binary operator or a unary operator * The true/false value indicates whether it is a binary operator or a unary operator
@ -1841,28 +1832,6 @@ class PHPExcel_Calculation {
} // function clearCalculationCache() } // function clearCalculationCache()
/**
* Get calculation cache expiration time
*
* @return float
*/
public function getCalculationCacheExpirationTime() {
return self::$_calculationCacheExpirationTime;
} // getCalculationCacheExpirationTime()
/**
* Set calculation cache expiration time
*
* @param float $pValue
*/
public function setCalculationCacheExpirationTime($pValue = 15) {
self::$_calculationCacheExpirationTime = $pValue;
} // function setCalculationCacheExpirationTime()
/** /**
* Get the currently defined locale code * Get the currently defined locale code
* *
@ -2280,32 +2249,20 @@ class PHPExcel_Calculation {
} }
} }
// Is calculation cacheing enabled? // Is calculation cacheing enabled?
if ($cellID !== NULL) { if (($cellID !== NULL) && (self::$_calculationCacheEnabled)) {
if (self::$_calculationCacheEnabled) {
// Is the value present in calculation cache? // Is the value present in calculation cache?
// echo 'Testing cache value<br />'; $this->_writeDebug('Testing cache for cell ', $cellID);
if (isset(self::$_calculationCache[$wsTitle][$cellID])) { if (isset(self::$_calculationCache[$wsTitle][$cellID])) {
// echo 'Value is in cache<br />'; // echo 'Value is in cache<br />';
$this->_writeDebug('Testing cache value for cell '.$cellID); $this->_writeDebug('Retrieving value for ', $cellID, ' from cache');
// Is cache still valid?
if ((microtime(true) - self::$_calculationCache[$wsTitle][$cellID]['time']) < self::$_calculationCacheExpirationTime) {
// echo 'Cache time is still valid<br />';
$this->_writeDebug('Retrieving value for '.$cellID.' from cache');
// Return the cached result // Return the cached result
$returnValue = self::$_calculationCache[$wsTitle][$cellID]['data']; $returnValue = self::$_calculationCache[$wsTitle][$cellID];
// echo 'Retrieving data value of '.$returnValue.' for '.$cellID.' from cache<br />'; // echo 'Retrieving data value of '.$returnValue.' for '.$cellID.' from cache<br />';
if (is_array($returnValue)) { if (is_array($returnValue)) {
$returnValue = PHPExcel_Calculation_Functions::flattenArray($returnValue); $returnValue = PHPExcel_Calculation_Functions::flattenArray($returnValue);
return array_shift($returnValue); return array_shift($returnValue);
} }
return $returnValue; return $returnValue;
} else {
// echo 'Cache has expired<br />';
$this->_writeDebug('Cache value for '.$cellID.' has expired');
// Clear the cache if it's no longer valid
unset(self::$_calculationCache[$wsTitle][$cellID]);
}
}
} }
} }
@ -2333,11 +2290,8 @@ class PHPExcel_Calculation {
array_pop($this->debugLogStack); array_pop($this->debugLogStack);
// Save to calculation cache // Save to calculation cache
if ($cellID !== NULL) { if (($cellID !== NULL) && (self::$_calculationCacheEnabled)) {
if (self::$_calculationCacheEnabled) { self::$_calculationCache[$wsTitle][$cellID] = $cellValue;
self::$_calculationCache[$wsTitle][$cellID]['time'] = microtime(true);
self::$_calculationCache[$wsTitle][$cellID]['data'] = $cellValue;
}
} }
// Return the calculated value // Return the calculated value
@ -3032,9 +2986,9 @@ class PHPExcel_Calculation {
// Log what we're doing // Log what we're doing
if ($token == ':') { if ($token == ':') {
$this->_writeDebug('Evaluating Range '.$this->_showValue($operand1Data['reference']).$token.$this->_showValue($operand2Data['reference'])); $this->_writeDebug('Evaluating Range ', $this->_showValue($operand1Data['reference']), $token, $this->_showValue($operand2Data['reference']));
} else { } else {
$this->_writeDebug('Evaluating '.$this->_showValue($operand1).' '.$token.' '.$this->_showValue($operand2)); $this->_writeDebug('Evaluating ', $this->_showValue($operand1), ' ', $token, ' ', $this->_showValue($operand2));
} }
// Process the operation in the appropriate manner // Process the operation in the appropriate manner
@ -3135,13 +3089,13 @@ class PHPExcel_Calculation {
$matrixResult = $matrix->concat($operand2); $matrixResult = $matrix->concat($operand2);
$result = $matrixResult->getArray(); $result = $matrixResult->getArray();
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
$this->_writeDebug('JAMA Matrix Exception: '.$ex->getMessage()); $this->_writeDebug('JAMA Matrix Exception: ', $ex->getMessage());
$result = '#VALUE!'; $result = '#VALUE!';
} }
} else { } else {
$result = '"'.str_replace('""','"',self::_unwrapResult($operand1,'"').self::_unwrapResult($operand2,'"')).'"'; $result = '"'.str_replace('""','"',self::_unwrapResult($operand1,'"').self::_unwrapResult($operand2,'"')).'"';
} }
$this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); $this->_writeDebug('Evaluation Result is ', $this->_showTypeDetails($result));
$stack->push('Value',$result); $stack->push('Value',$result);
break; break;
case '|' : // Intersect case '|' : // Intersect
@ -3155,7 +3109,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);
$this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($cellIntersect)); $this->_writeDebug('Evaluation Result is ', $this->_showTypeDetails($cellIntersect));
$stack->push('Value',$cellIntersect,$cellRef); $stack->push('Value',$cellIntersect,$cellRef);
break; break;
} }
@ -3167,11 +3121,11 @@ class PHPExcel_Calculation {
$arg = $arg['value']; $arg = $arg['value'];
if ($token === '~') { if ($token === '~') {
// echo 'Token is a negation operator<br />'; // echo 'Token is a negation operator<br />';
$this->_writeDebug('Evaluating Negation of '.$this->_showValue($arg)); $this->_writeDebug('Evaluating Negation of ', $this->_showValue($arg));
$multiplier = -1; $multiplier = -1;
} else { } else {
// echo 'Token is a percentile operator<br />'; // echo 'Token is a percentile operator<br />';
$this->_writeDebug('Evaluating Percentile of '.$this->_showValue($arg)); $this->_writeDebug('Evaluating Percentile of ', $this->_showValue($arg));
$multiplier = 0.01; $multiplier = 0.01;
} }
if (is_array($arg)) { if (is_array($arg)) {
@ -3181,10 +3135,10 @@ class PHPExcel_Calculation {
$matrixResult = $matrix1->arrayTimesEquals($multiplier); $matrixResult = $matrix1->arrayTimesEquals($multiplier);
$result = $matrixResult->getArray(); $result = $matrixResult->getArray();
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
$this->_writeDebug('JAMA Matrix Exception: '.$ex->getMessage()); $this->_writeDebug('JAMA Matrix Exception: ', $ex->getMessage());
$result = '#VALUE!'; $result = '#VALUE!';
} }
$this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); $this->_writeDebug('Evaluation Result is ', $this->_showTypeDetails($result));
$stack->push('Value',$result); $stack->push('Value',$result);
} else { } else {
$this->_executeNumericBinaryOperation($cellID,$multiplier,$arg,'*','arrayTimesEquals',$stack); $this->_executeNumericBinaryOperation($cellID,$multiplier,$arg,'*','arrayTimesEquals',$stack);
@ -3208,23 +3162,23 @@ class PHPExcel_Calculation {
} }
$matches[2] = trim($matches[2],"\"'"); $matches[2] = trim($matches[2],"\"'");
// 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) {
$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');
} }
$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 {
// echo '$cellRef='.$cellRef.' in current worksheet<br />'; // echo '$cellRef='.$cellRef.' in current worksheet<br />';
$this->_writeDebug('Evaluating Cell Range '.$cellRef.' in current worksheet'); $this->_writeDebug('Evaluating Cell Range ', $cellRef, ' in current worksheet');
if ($pCellParent !== NULL) { if ($pCellParent !== NULL) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent, false); $cellValue = $this->extractCellRange($cellRef, $pCellParent, false);
} else { } else {
return $this->_raiseFormulaError('Unable to access Cell Reference'); return $this->_raiseFormulaError('Unable to access Cell Reference');
} }
$this->_writeDebug('Evaluation Result for cells '.$cellRef.' is '.$this->_showTypeDetails($cellValue)); $this->_writeDebug('Evaluation Result for cells ', $cellRef, ' is ', $this->_showTypeDetails($cellValue));
} }
} }
} else { } else {
@ -3241,7 +3195,7 @@ class PHPExcel_Calculation {
return $this->_raiseFormulaError('Unable to access External Workbook'); return $this->_raiseFormulaError('Unable to access External Workbook');
} }
// 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) {
if ($pCellParent->getParent()->getSheetByName($matches[2])->cellExists($cellRef)) { if ($pCellParent->getParent()->getSheetByName($matches[2])->cellExists($cellRef)) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false); $cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
@ -3252,18 +3206,18 @@ class PHPExcel_Calculation {
} else { } else {
return $this->_raiseFormulaError('Unable to access Cell Reference'); return $this->_raiseFormulaError('Unable to access Cell Reference');
} }
$this->_writeDebug('Evaluation Result for cell '.$cellRef.' in worksheet '.$matches[2].' is '.$this->_showTypeDetails($cellValue)); $this->_writeDebug('Evaluation Result for cell ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->_showTypeDetails($cellValue));
// $cellRef = $matches[2].'!'.$cellRef; // $cellRef = $matches[2].'!'.$cellRef;
} else { } else {
// echo '$cellRef='.$cellRef.' in current worksheet<br />'; // echo '$cellRef='.$cellRef.' in current worksheet<br />';
$this->_writeDebug('Evaluating Cell '.$cellRef.' in current worksheet'); $this->_writeDebug('Evaluating Cell ', $cellRef, ' in current worksheet');
if ($pCellParent->cellExists($cellRef)) { if ($pCellParent->cellExists($cellRef)) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent, false); $cellValue = $this->extractCellRange($cellRef, $pCellParent, false);
$pCell->attach($pCellParent); $pCell->attach($pCellParent);
} else { } else {
$cellValue = null; $cellValue = null;
} }
$this->_writeDebug('Evaluation Result for cell '.$cellRef.' is '.$this->_showTypeDetails($cellValue)); $this->_writeDebug('Evaluation Result for cell ', $cellRef, ' is ', $this->_showTypeDetails($cellValue));
} }
} }
} }
@ -3276,7 +3230,7 @@ class PHPExcel_Calculation {
$argCount = $stack->pop(); $argCount = $stack->pop();
$argCount = $argCount['value']; $argCount = $argCount['value'];
if ($functionName != 'MKMATRIX') { if ($functionName != 'MKMATRIX') {
$this->_writeDebug('Evaluating Function '.self::_localeFunc($functionName).'() with '.(($argCount == 0) ? 'no' : $argCount).' argument'.(($argCount == 1) ? '' : 's')); $this->_writeDebug('Evaluating Function ', self::_localeFunc($functionName), '() with ', (($argCount == 0) ? 'no' : $argCount), ' argument', (($argCount == 1) ? '' : 's'));
} }
if ((isset(self::$_PHPExcelFunctions[$functionName])) || (isset(self::$_controlFunctions[$functionName]))) { // function if ((isset(self::$_PHPExcelFunctions[$functionName])) || (isset(self::$_controlFunctions[$functionName]))) { // function
if (isset(self::$_PHPExcelFunctions[$functionName])) { if (isset(self::$_PHPExcelFunctions[$functionName])) {
@ -3321,28 +3275,28 @@ class PHPExcel_Calculation {
if ($functionName != 'MKMATRIX') { if ($functionName != 'MKMATRIX') {
if ($this->writeDebugLog) { if ($this->writeDebugLog) {
krsort($argArrayVals); krsort($argArrayVals);
$this->_writeDebug('Evaluating '. self::_localeFunc($functionName).'( '.implode(self::$_localeArgumentSeparator.' ',PHPExcel_Calculation_Functions::flattenArray($argArrayVals)).' )'); $this->_writeDebug('Evaluating ', self::_localeFunc($functionName), '( '.implode(self::$_localeArgumentSeparator.' ',PHPExcel_Calculation_Functions::flattenArray($argArrayVals)).' )');
} }
} }
// Process each argument in turn, building the return value as an array // Process each argument in turn, building the return value as an array
// if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) { // if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) {
// $operand1 = $args[1]; // $operand1 = $args[1];
// $this->_writeDebug('Argument is a matrix: '.$this->_showValue($operand1)); // $this->_writeDebug('Argument is a matrix: ', $this->_showValue($operand1));
// $result = array(); // $result = array();
// $row = 0; // $row = 0;
// foreach($operand1 as $args) { // foreach($operand1 as $args) {
// if (is_array($args)) { // if (is_array($args)) {
// foreach($args as $arg) { // foreach($args as $arg) {
// $this->_writeDebug('Evaluating '.self::_localeFunc($functionName).'( '.$this->_showValue($arg).' )'); // $this->_writeDebug('Evaluating ', self::_localeFunc($functionName), '( '.$this->_showValue($arg), ' )');
// $r = call_user_func_array($functionCall,$arg); // $r = call_user_func_array($functionCall,$arg);
// $this->_writeDebug('Evaluation Result for '.self::_localeFunc($functionName).'() function call is '.$this->_showTypeDetails($r)); // $this->_writeDebug('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($r));
// $result[$row][] = $r; // $result[$row][] = $r;
// } // }
// ++$row; // ++$row;
// } else { // } else {
// $this->_writeDebug('Evaluating '.self::_localeFunc($functionName).'( '.$this->_showValue($args).' )'); // $this->_writeDebug('Evaluating ', self::_localeFunc($functionName), '( '.$this->_showValue($args), ' )');
// $r = call_user_func_array($functionCall,$args); // $r = call_user_func_array($functionCall,$args);
// $this->_writeDebug('Evaluation Result for '.self::_localeFunc($functionName).'() function call is '.$this->_showTypeDetails($r)); // $this->_writeDebug('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($r));
// $result[] = $r; // $result[] = $r;
// } // }
// } // }
@ -3362,7 +3316,7 @@ class PHPExcel_Calculation {
} }
// } // }
if ($functionName != 'MKMATRIX') { if ($functionName != 'MKMATRIX') {
$this->_writeDebug('Evaluation Result for '.self::_localeFunc($functionName).'() function call is '.$this->_showTypeDetails($result)); $this->_writeDebug('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($result));
} }
$stack->push('Value',self::_wrapResult($result)); $stack->push('Value',self::_wrapResult($result));
} }
@ -3373,7 +3327,7 @@ class PHPExcel_Calculation {
$excelConstant = strtoupper($token); $excelConstant = strtoupper($token);
// echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />'; // echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
$stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]); $stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]);
$this->_writeDebug('Evaluating Constant '.$excelConstant.' as '.$this->_showTypeDetails(self::$_ExcelConstants[$excelConstant])); $this->_writeDebug('Evaluating Constant ', $excelConstant, ' as ', $this->_showTypeDetails(self::$_ExcelConstants[$excelConstant]));
} elseif ((is_numeric($token)) || ($token === NULL) || (is_bool($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) { } elseif ((is_numeric($token)) || ($token === NULL) || (is_bool($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) {
// echo 'Token is a number, boolean, string, null or an Excel error<br />'; // echo 'Token is a number, boolean, string, null or an Excel error<br />';
$stack->push('Value',$token); $stack->push('Value',$token);
@ -3382,10 +3336,10 @@ class PHPExcel_Calculation {
// echo 'Token is a named range<br />'; // echo 'Token is a named range<br />';
$namedRange = $matches[6]; $namedRange = $matches[6];
// echo 'Named Range is '.$namedRange.'<br />'; // echo 'Named Range is '.$namedRange.'<br />';
$this->_writeDebug('Evaluating Named Range '.$namedRange); $this->_writeDebug('Evaluating Named Range ', $namedRange);
$cellValue = $this->extractNamedRange($namedRange, ((null !== $pCell) ? $pCellParent : null), false); $cellValue = $this->extractNamedRange($namedRange, ((null !== $pCell) ? $pCellParent : null), false);
$pCell->attach($pCellParent); $pCell->attach($pCellParent);
$this->_writeDebug('Evaluation Result for named range '.$namedRange.' is '.$this->_showTypeDetails($cellValue)); $this->_writeDebug('Evaluation Result for named range ', $namedRange, ' is ', $this->_showTypeDetails($cellValue));
$stack->push('Named Range',$cellValue,$namedRange); $stack->push('Named Range',$cellValue,$namedRange);
} else { } else {
return $this->_raiseFormulaError("undefined variable '$token'"); return $this->_raiseFormulaError("undefined variable '$token'");
@ -3415,12 +3369,12 @@ class PHPExcel_Calculation {
// If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations // If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
if ($operand > '' && $operand{0} == '#') { if ($operand > '' && $operand{0} == '#') {
$stack->push('Value', $operand); $stack->push('Value', $operand);
$this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($operand)); $this->_writeDebug('Evaluation Result is ', $this->_showTypeDetails($operand));
return false; return false;
} elseif (!PHPExcel_Shared_String::convertToNumberIfFraction($operand)) { } elseif (!PHPExcel_Shared_String::convertToNumberIfFraction($operand)) {
// If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations // If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations
$stack->push('Value', '#VALUE!'); $stack->push('Value', '#VALUE!');
$this->_writeDebug('Evaluation Result is a '.$this->_showTypeDetails('#VALUE!')); $this->_writeDebug('Evaluation Result is a ', $this->_showTypeDetails('#VALUE!'));
return false; return false;
} }
} }
@ -3437,14 +3391,14 @@ class PHPExcel_Calculation {
$result = array(); $result = array();
if ((is_array($operand1)) && (!is_array($operand2))) { if ((is_array($operand1)) && (!is_array($operand2))) {
foreach($operand1 as $x => $operandData) { foreach($operand1 as $x => $operandData) {
$this->_writeDebug('Evaluating Comparison '.$this->_showValue($operandData).' '.$operation.' '.$this->_showValue($operand2)); $this->_writeDebug('Evaluating Comparison ', $this->_showValue($operandData), ' ', $operation, ' ', $this->_showValue($operand2));
$this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2,$operation,$stack); $this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2,$operation,$stack);
$r = $stack->pop(); $r = $stack->pop();
$result[$x] = $r['value']; $result[$x] = $r['value'];
} }
} elseif ((!is_array($operand1)) && (is_array($operand2))) { } elseif ((!is_array($operand1)) && (is_array($operand2))) {
foreach($operand2 as $x => $operandData) { foreach($operand2 as $x => $operandData) {
$this->_writeDebug('Evaluating Comparison '.$this->_showValue($operand1).' '.$operation.' '.$this->_showValue($operandData)); $this->_writeDebug('Evaluating Comparison ', $this->_showValue($operand1), ' ', $operation, ' ', $this->_showValue($operandData));
$this->_executeBinaryComparisonOperation($cellID,$operand1,$operandData,$operation,$stack); $this->_executeBinaryComparisonOperation($cellID,$operand1,$operandData,$operation,$stack);
$r = $stack->pop(); $r = $stack->pop();
$result[$x] = $r['value']; $result[$x] = $r['value'];
@ -3452,14 +3406,14 @@ class PHPExcel_Calculation {
} else { } else {
if (!$recursingArrays) { self::_checkMatrixOperands($operand1,$operand2,2); } if (!$recursingArrays) { self::_checkMatrixOperands($operand1,$operand2,2); }
foreach($operand1 as $x => $operandData) { foreach($operand1 as $x => $operandData) {
$this->_writeDebug('Evaluating Comparison '.$this->_showValue($operandData).' '.$operation.' '.$this->_showValue($operand2[$x])); $this->_writeDebug('Evaluating Comparison ', $this->_showValue($operandData), ' ', $operation, ' ', $this->_showValue($operand2[$x]));
$this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2[$x],$operation,$stack,true); $this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2[$x],$operation,$stack,true);
$r = $stack->pop(); $r = $stack->pop();
$result[$x] = $r['value']; $result[$x] = $r['value'];
} }
} }
// Log the result details // Log the result details
$this->_writeDebug('Comparison Evaluation Result is '.$this->_showTypeDetails($result)); $this->_writeDebug('Comparison Evaluation Result is ', $this->_showTypeDetails($result));
// And push the result onto the stack // And push the result onto the stack
$stack->push('Array',$result); $stack->push('Array',$result);
return true; return true;
@ -3498,7 +3452,7 @@ class PHPExcel_Calculation {
} }
// Log the result details // Log the result details
$this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); $this->_writeDebug('Evaluation Result is ', $this->_showTypeDetails($result));
// And push the result onto the stack // And push the result onto the stack
$stack->push('Value',$result); $stack->push('Value',$result);
return true; return true;
@ -3536,7 +3490,7 @@ class PHPExcel_Calculation {
$matrixResult = $matrix->$matrixFunction($operand2); $matrixResult = $matrix->$matrixFunction($operand2);
$result = $matrixResult->getArray(); $result = $matrixResult->getArray();
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
$this->_writeDebug('JAMA Matrix Exception: '.$ex->getMessage()); $this->_writeDebug('JAMA Matrix Exception: ', $ex->getMessage());
$result = '#VALUE!'; $result = '#VALUE!';
} }
} else { } else {
@ -3563,7 +3517,7 @@ class PHPExcel_Calculation {
if ($operand2 == 0) { if ($operand2 == 0) {
// Trap for Divide by Zero error // Trap for Divide by Zero error
$stack->push('Value','#DIV/0!'); $stack->push('Value','#DIV/0!');
$this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails('#DIV/0!')); $this->_writeDebug('Evaluation Result is ', $this->_showTypeDetails('#DIV/0!'));
return false; return false;
} else { } else {
$result = $operand1/$operand2; $result = $operand1/$operand2;
@ -3578,18 +3532,19 @@ class PHPExcel_Calculation {
} }
// Log the result details // Log the result details
$this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); $this->_writeDebug('Evaluation Result is ', $this->_showTypeDetails($result));
// And push the result onto the stack // And push the result onto the stack
$stack->push('Value',$result); $stack->push('Value',$result);
return true; return true;
} // function _executeNumericBinaryOperation() } // function _executeNumericBinaryOperation()
private function _writeDebug($message) { private function _writeDebug() {
// Only write the debug log if logging is enabled // Only write the debug log if logging is enabled
if ($this->writeDebugLog) { if ($this->writeDebugLog) {
$message = implode('', func_get_args());
if ($this->echoDebugLog) { if ($this->echoDebugLog) {
echo implode(' -> ',$this->debugLogStack).' -> '.$message,'<br />'; echo implode(' -> ', $this->debugLogStack) . ' -> ' . $message , PHP_EOL;
} }
$this->debugLog[] = implode(' -> ', $this->debugLogStack) . ' -> ' . $message; $this->debugLog[] = implode(' -> ', $this->debugLogStack) . ' -> ' . $message;
} }

View File

@ -51,18 +51,11 @@ class PHPExcel_Cell
private static $_valueBinder = NULL; private static $_valueBinder = NULL;
/** /**
* Column of the cell * Cell Address (e.g. A1)
* *
* @var string * @var string
*/ */
private $_column; private $_coordinate;
/**
* Row of the cell
*
* @var int
*/
private $_row;
/** /**
* Value of the cell * Value of the cell
@ -143,8 +136,7 @@ class PHPExcel_Cell
public function __construct($pColumn = 'A', $pRow = 1, $pValue = NULL, $pDataType = NULL, PHPExcel_Worksheet $pSheet = NULL) public function __construct($pColumn = 'A', $pRow = 1, $pValue = NULL, $pDataType = NULL, PHPExcel_Worksheet $pSheet = NULL)
{ {
// Initialise cell coordinate // Initialise cell coordinate
$this->_column = strtoupper($pColumn); $this->_coordinate = strtoupper($pColumn) . $pRow;
$this->_row = $pRow;
// Initialise cell value // Initialise cell value
$this->_value = $pValue; $this->_value = $pValue;
@ -174,7 +166,8 @@ class PHPExcel_Cell
*/ */
public function getColumn() public function getColumn()
{ {
return $this->_column; list($column) = sscanf($this->_coordinate, '%[A-Z]%d');
return $column;
} }
/** /**
@ -184,7 +177,8 @@ class PHPExcel_Cell
*/ */
public function getRow() public function getRow()
{ {
return $this->_row; list(,$row) = sscanf($this->_coordinate, '%[A-Z]%d');
return $row;
} }
/** /**
@ -194,7 +188,7 @@ class PHPExcel_Cell
*/ */
public function getCoordinate() public function getCoordinate()
{ {
return $this->_column . $this->_row; return $this->_coordinate;
} }
/** /**