Minor performance tweaks and adjustments to Excel functions to handle a few envelope test cases

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85742 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-01-25 22:07:35 +00:00
parent a77c44d4e6
commit 2cce9b754d
16 changed files with 137 additions and 92 deletions

View File

@ -184,7 +184,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
if ($this->_currentObject !== NULL) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
@ -202,7 +202,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
public function __construct(PHPExcel_Worksheet $parent, $arguments) {
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) {
if ($this->_cachePrefix === NULL) {
$baseUnique = $this->_getUniqueID();
$this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
$this->_cacheTime = $cacheTime;

View File

@ -2152,8 +2152,8 @@ class PHPExcel_Calculation {
}
// Read the formula from the cell
if (is_null($pCell)) {
return null;
if ($pCell === NULL) {
return NULL;
}
if ($resetLog) {
@ -2188,7 +2188,7 @@ class PHPExcel_Calculation {
$result = array_shift($testResult);
}
if (is_null($result)) {
if ($result === NULL) {
return 0;
} elseif((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
return PHPExcel_Calculation_Functions::NaN();
@ -2268,14 +2268,14 @@ class PHPExcel_Calculation {
if (!isset($formula{0})) return self::_wrapResult($formula);
$wsTitle = "\x00Wrk";
if (!is_null($pCell)) {
if ($pCell !== NULL) {
$pCellParent = $pCell->getParent();
if (!is_null($pCellParent)) {
if ($pCellParent !== NULL) {
$wsTitle = $pCellParent->getTitle();
}
}
// Is calculation cacheing enabled?
if (!is_null($cellID)) {
if ($cellID !== NULL) {
if (self::$_calculationCacheEnabled) {
// Is the value present in calculation cache?
// echo 'Testing cache value<br />';
@ -2328,7 +2328,7 @@ class PHPExcel_Calculation {
array_pop($this->debugLogStack);
// Save to calculation cache
if (!is_null($cellID)) {
if ($cellID !== NULL) {
if (self::$_calculationCacheEnabled) {
self::$_calculationCache[$wsTitle][$cellID]['time'] = microtime(true);
self::$_calculationCache[$wsTitle][$cellID]['data'] = $cellValue;
@ -2534,7 +2534,7 @@ class PHPExcel_Calculation {
$value = array_pop($testArray);
}
if (is_null($value)) {
if ($value === NULL) {
return 'a NULL value';
} elseif (is_float($value)) {
$typeString = 'a floating point number';
@ -2617,12 +2617,12 @@ class PHPExcel_Calculation {
// Convert infix to postfix notation
private function _parseFormula($formula, PHPExcel_Cell $pCell = null) {
if (($formula = self::_convertMatrixReferences(trim($formula))) === false) {
return false;
return FALSE;
}
// 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
$pCellParent = (!is_null($pCell)) ? $pCell->getParent() : null;
$pCellParent = ($pCell !== NULL) ? $pCell->getParent() : NULL;
// Binary Operators
// These operators always work on two values
@ -2715,7 +2715,7 @@ class PHPExcel_Calculation {
// echo 'Element is a Closing bracket<br />';
$expectingOperand = false;
while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
if (is_null($o2)) return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"');
if ($o2 === NULL) return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"');
else $output[] = $o2;
}
$d = $stack->last(2);
@ -2794,7 +2794,7 @@ class PHPExcel_Calculation {
} elseif ($opCharacter == ',') { // Is this the separator for function arguments?
// echo 'Element is a Function argument separator<br />';
while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
if (is_null($o2)) return $this->_raiseFormulaError("Formula Error: Unexpected ,");
if ($o2 === NULL) return $this->_raiseFormulaError("Formula Error: Unexpected ,");
else $output[] = $o2; // pop the argument expression stuff and push onto the output
}
// If we've a comma when we're expecting an operand, then what we actually have is a null operand;
@ -2885,13 +2885,13 @@ class PHPExcel_Calculation {
if ((is_integer($startRowColRef)) && (ctype_digit($val)) &&
($startRowColRef <= 1048576) && ($val <= 1048576)) {
// Row range
$endRowColRef = (!is_null($pCellParent)) ? $pCellParent->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007
$endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007
$output[count($output)-1]['value'] = $rangeWS1.'A'.$startRowColRef;
$val = $rangeWS2.$endRowColRef.$val;
} elseif ((ctype_alpha($startRowColRef)) && (ctype_alpha($val)) &&
(strlen($startRowColRef) <= 3) && (strlen($val) <= 3)) {
// Column range
$endRowColRef = (!is_null($pCellParent)) ? $pCellParent->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007
$endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007
$output[count($output)-1]['value'] = $rangeWS1.strtoupper($startRowColRef).'1';
$val = $rangeWS2.$val.$endRowColRef;
}
@ -2976,7 +2976,7 @@ class PHPExcel_Calculation {
}
}
while (!is_null($op = $stack->pop())) { // pop everything off the stack and push onto output
while (($op = $stack->pop()) !== NULL) { // pop everything off the stack and push onto output
if ($opCharacter['value'] == '(') return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
$output[] = $op;
}
@ -2990,7 +2990,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),
// so we store the parent worksheet so that we can re-attach it when necessary
$pCellParent = (!is_null($pCell)) ? $pCell->getParent() : null;
$pCellParent = ($pCell !== NULL) ? $pCell->getParent() : null;
$stack = new PHPExcel_Token_Stack;
// Loop through each token in turn
@ -3003,11 +3003,11 @@ class PHPExcel_Calculation {
if (isset(self::$_binaryOperators[$token])) {
// echo 'Token is a binary operator<br />';
// We must have two operands, error if we don't
if (is_null($operand2Data = $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
if (is_null($operand1Data = $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
if (($operand2Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
if (($operand1Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
$operand1 = $operand1Data['value'];
if ((is_null($operand1Data['reference'])) && (is_array($operand1))) {
if (($operand1Data['reference'] === NULL) && (is_array($operand1))) {
$rowKey = array_shift(array_keys($operand1));
$colKey = array_shift(array_keys($operand1[$rowKey]));
if (ctype_upper($colKey)) {
@ -3015,7 +3015,7 @@ class PHPExcel_Calculation {
}
}
$operand2 = $operand2Data['value'];
if ((is_null($operand2Data['reference'])) && (is_array($operand2))) {
if (($operand2Data['reference'] === NULL) && (is_array($operand2))) {
$rowKey = array_shift(array_keys($operand2));
$colKey = array_shift(array_keys($operand2[$rowKey]));
if (ctype_upper($colKey)) {
@ -3047,7 +3047,7 @@ class PHPExcel_Calculation {
if (strpos($operand1Data['reference'],'!') !== false) {
list($sheet1,$operand1Data['reference']) = explode('!',$operand1Data['reference']);
} else {
$sheet1 = (!is_null($pCellParent)) ? $pCellParent->getTitle() : '';
$sheet1 = ($pCellParent !== NULL) ? $pCellParent->getTitle() : '';
}
if (strpos($operand2Data['reference'],'!') !== false) {
list($sheet2,$operand2Data['reference']) = explode('!',$operand2Data['reference']);
@ -3055,7 +3055,7 @@ class PHPExcel_Calculation {
$sheet2 = $sheet1;
}
if ($sheet1 == $sheet2) {
if (is_null($operand1Data['reference'])) {
if ($operand1Data['reference'] === NULL) {
if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
$operand1Data['reference'] = $pCell->getColumn().$operand1Data['value'];
} elseif (trim($operand1Data['reference']) == '') {
@ -3064,7 +3064,7 @@ class PHPExcel_Calculation {
$operand1Data['reference'] = $operand1Data['value'].$pCell->getRow();
}
}
if (is_null($operand2Data['reference'])) {
if ($operand2Data['reference'] === NULL) {
if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
$operand2Data['reference'] = $pCell->getColumn().$operand2Data['value'];
} elseif (trim($operand2Data['reference']) == '') {
@ -3082,7 +3082,7 @@ class PHPExcel_Calculation {
$oRow[] = $oCR[1];
}
$cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow);
if (!is_null($pCellParent)) {
if ($pCellParent !== NULL) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($sheet1), false);
} else {
return $this->_raiseFormulaError('Unable to access Cell Reference');
@ -3156,7 +3156,7 @@ class PHPExcel_Calculation {
// if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
} elseif (($token === '~') || ($token === '%')) {
// echo 'Token is a unary operator<br />';
if (is_null($arg = $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
if (($arg = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
$arg = $arg['value'];
if ($token === '~') {
// echo 'Token is a negation operator<br />';
@ -3188,7 +3188,7 @@ class PHPExcel_Calculation {
// echo 'Element '.$token.' is a Cell reference<br />';
if (isset($matches[8])) {
// echo 'Reference is a Range of cells<br />';
if (is_null($pCell)) {
if ($pCell === NULL) {
// We can't access the range, so return a REF error
$cellValue = PHPExcel_Calculation_Functions::REF();
} else {
@ -3202,7 +3202,7 @@ class PHPExcel_Calculation {
$matches[2] = trim($matches[2],"\"'");
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
$this->_writeDebug('Evaluating Cell Range '.$cellRef.' in worksheet '.$matches[2]);
if (!is_null($pCellParent)) {
if ($pCellParent !== NULL) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
} else {
return $this->_raiseFormulaError('Unable to access Cell Reference');
@ -3212,7 +3212,7 @@ class PHPExcel_Calculation {
} else {
// echo '$cellRef='.$cellRef.' in current worksheet<br />';
$this->_writeDebug('Evaluating Cell Range '.$cellRef.' in current worksheet');
if (!is_null($pCellParent)) {
if ($pCellParent !== NULL) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent, false);
} else {
return $this->_raiseFormulaError('Unable to access Cell Reference');
@ -3222,7 +3222,7 @@ class PHPExcel_Calculation {
}
} else {
// echo 'Reference is a single Cell<br />';
if (is_null($pCell)) {
if ($pCell !== NULL) {
// We can't access the cell, so return a REF error
$cellValue = PHPExcel_Calculation_Functions::REF();
} else {
@ -3235,7 +3235,7 @@ class PHPExcel_Calculation {
}
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
$this->_writeDebug('Evaluating Cell '.$cellRef.' in worksheet '.$matches[2]);
if (!is_null($pCellParent)) {
if ($pCellParent !== NULL) {
if ($pCellParent->getParent()->getSheetByName($matches[2])->cellExists($cellRef)) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
$pCell->attach($pCellParent);
@ -3290,7 +3290,7 @@ class PHPExcel_Calculation {
if (($passByReference) &&
(isset(self::$_PHPExcelFunctions[$functionName]['passByReference'][$a])) &&
(self::$_PHPExcelFunctions[$functionName]['passByReference'][$a])) {
if (is_null($arg['reference'])) {
if ($arg['reference'] === NULL) {
$args[] = $cellID;
if ($functionName != 'MKMATRIX') { $argArrayVals[] = $this->_showValue($cellID); }
} else {
@ -3367,7 +3367,7 @@ class PHPExcel_Calculation {
// echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
$stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]);
$this->_writeDebug('Evaluating Constant '.$excelConstant.' as '.$this->_showTypeDetails(self::$_ExcelConstants[$excelConstant]));
} elseif ((is_numeric($token)) || (is_null($token)) || (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 />';
$stack->push('Value',$token);
// if the token is a named range, push the named range name onto the stack
@ -3611,7 +3611,7 @@ class PHPExcel_Calculation {
$returnValue = array ();
// echo 'extractCellRange('.$pRange.')<br />';
if (!is_null($pSheet)) {
if ($pSheet !== NULL) {
// echo 'Passed sheet name is '.$pSheet->getTitle().'<br />';
// echo 'Range reference is '.$pRange.'<br />';
if (strpos ($pRange, '!') !== false) {
@ -3667,7 +3667,7 @@ class PHPExcel_Calculation {
$returnValue = array ();
// echo 'extractNamedRange('.$pRange.')<br />';
if (!is_null($pSheet)) {
if ($pSheet !== NULL) {
// echo 'Current sheet name is '.$pSheet->getTitle().'<br />';
// echo 'Range reference is '.$pRange.'<br />';
if (strpos ($pRange, '!') !== false) {
@ -3681,7 +3681,7 @@ class PHPExcel_Calculation {
// Named range?
$namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
if (!is_null($namedRange)) {
if ($namedRange !== NULL) {
$pSheet = $namedRange->getWorksheet();
// echo 'Named Range '.$pRange.' (';
$pRange = $namedRange->getRange();

View File

@ -182,7 +182,7 @@ class PHPExcel_Calculation_DateTime {
$retValue = (float) $excelDateTime;
break;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
$retValue = (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateTime) - 3600;
$retValue = (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateTime);
break;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
$retValue = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateTime);
@ -204,9 +204,21 @@ class PHPExcel_Calculation_DateTime {
* depending on the value of the ReturnDateType flag
*/
public static function DATE($year = 0, $month = 1, $day = 1) {
$year = (integer) PHPExcel_Calculation_Functions::flattenSingleValue($year);
$month = (integer) PHPExcel_Calculation_Functions::flattenSingleValue($month);
$day = (integer) PHPExcel_Calculation_Functions::flattenSingleValue($day);
$year = PHPExcel_Calculation_Functions::flattenSingleValue($year);
$month = PHPExcel_Calculation_Functions::flattenSingleValue($month);
$day = PHPExcel_Calculation_Functions::flattenSingleValue($day);
$year = ($year !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0;
$month = ($month !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0;
$day = ($day !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0;
if ((!is_numeric($year)) ||
(!is_numeric($month)) ||
(!is_numeric($day))) {
return PHPExcel_Calculation_Functions::VALUE();
}
$year = (integer) $year;
$month = (integer) $month;
$day = (integer) $day;
$baseYear = PHPExcel_Shared_Date::getExcelCalendar();
// Validate parameters
@ -312,7 +324,7 @@ class PHPExcel_Calculation_DateTime {
return (float) PHPExcel_Shared_Date::FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
break;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour-1, $minute, $second)); // -2147468400; // -2147472000 + 3600
return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600
break;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
$dayAdjust = 0;
@ -402,6 +414,8 @@ class PHPExcel_Calculation_DateTime {
if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
// Execute function
if ($PHPDateArray['year'] == '') { $PHPDateArray['year'] = strftime('%Y'); }
if ($PHPDateArray['year'] < 1900)
return PHPExcel_Calculation_Functions::VALUE();
if ($PHPDateArray['month'] == '') { $PHPDateArray['month'] = strftime('%m'); }
if ($PHPDateArray['day'] == '') { $PHPDateArray['day'] = strftime('%d'); }
$excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']));
@ -792,7 +806,7 @@ class PHPExcel_Calculation_DateTime {
if (!empty($dateArgs)) {
$holidayCountedArray = $holidayDates = array();
foreach ($dateArgs as $holidayDate) {
if ((!is_null($holidayDate)) && (trim($holidayDate) > '')) {
if (($holidayDate !== NULL) && (trim($holidayDate) > '')) {
if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
return PHPExcel_Calculation_Functions::VALUE();
}
@ -877,7 +891,14 @@ class PHPExcel_Calculation_DateTime {
*/
public static function DAYOFWEEK($dateValue = 1, $style = 1) {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
$style = floor(PHPExcel_Calculation_Functions::flattenSingleValue($style));
$style = PHPExcel_Calculation_Functions::flattenSingleValue($style);
if (!is_numeric($style)) {
return PHPExcel_Calculation_Functions::VALUE();
} elseif (($style < 1) || ($style > 3)) {
return PHPExcel_Calculation_Functions::NaN();
}
$style = floor($style);
if (is_string($dateValue = self::_getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE();
@ -899,7 +920,6 @@ class PHPExcel_Calculation_DateTime {
$firstDay = 0;
--$DoW;
break;
default:
}
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL) {
// Test for Excel's 1900 leap year, and introduce the error as required
@ -924,13 +944,14 @@ class PHPExcel_Calculation_DateTime {
*/
public static function WEEKOFYEAR($dateValue = 1, $method = 1) {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
$method = floor(PHPExcel_Calculation_Functions::flattenSingleValue($method));
$method = PHPExcel_Calculation_Functions::flattenSingleValue($method);
if (!is_numeric($method)) {
return PHPExcel_Calculation_Functions::VALUE();
} elseif (($method < 1) || ($method > 2)) {
return PHPExcel_Calculation_Functions::NaN();
}
$method = floor($method);
if (is_string($dateValue = self::_getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE();
@ -1107,11 +1128,12 @@ class PHPExcel_Calculation_DateTime {
*/
public static function EDATE($dateValue = 1, $adjustmentMonths = 0) {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
$adjustmentMonths = floor(PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths));
$adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
if (!is_numeric($adjustmentMonths)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$adjustmentMonths = floor($adjustmentMonths);
if (is_string($dateValue = self::_getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE();
@ -1146,11 +1168,12 @@ class PHPExcel_Calculation_DateTime {
*/
public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0) {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
$adjustmentMonths = floor(PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths));
$adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
if (!is_numeric($adjustmentMonths)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$adjustmentMonths = floor($adjustmentMonths);
if (is_string($dateValue = self::_getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE();
@ -1176,3 +1199,4 @@ class PHPExcel_Calculation_DateTime {
} // function EOMONTH()
} // class PHPExcel_Calculation_DateTime

View File

@ -2046,7 +2046,7 @@ class PHPExcel_Calculation_Engineering {
if (!is_numeric($value)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$fromMultiplier = 1;
$fromMultiplier = 1.0;
if (isset(self::$_conversionUnits[$fromUOM])) {
$unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
} else {
@ -2065,7 +2065,7 @@ class PHPExcel_Calculation_Engineering {
}
$value *= $fromMultiplier;
$toMultiplier = 1;
$toMultiplier = 1.0;
if (isset(self::$_conversionUnits[$toUOM])) {
$unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
} else {
@ -2086,12 +2086,12 @@ class PHPExcel_Calculation_Engineering {
return PHPExcel_Calculation_Functions::NA();
}
if ($fromUOM == $toUOM) {
return 1.0;
if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) {
return $value;
} elseif ($unitGroup1 == 'Temperature') {
if (($fromUOM == 'F') || ($fromUOM == 'fah')) {
if (($toUOM == 'F') || ($toUOM == 'fah')) {
return 1.0;
return $value;
} else {
$value = (($value - 32) / 1.8);
if (($toUOM == 'K') || ($toUOM == 'kel')) {
@ -2101,10 +2101,10 @@ class PHPExcel_Calculation_Engineering {
}
} elseif ((($fromUOM == 'K') || ($fromUOM == 'kel')) &&
(($toUOM == 'K') || ($toUOM == 'kel'))) {
return 1.0;
return $value;
} elseif ((($fromUOM == 'C') || ($fromUOM == 'cel')) &&
(($toUOM == 'C') || ($toUOM == 'cel'))) {
return 1.0;
return $value;
}
if (($toUOM == 'F') || ($toUOM == 'fah')) {
if (($fromUOM == 'K') || ($fromUOM == 'kel')) {

View File

@ -357,6 +357,11 @@ class PHPExcel_Calculation_MathTrig {
public static function INT($number) {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
if (is_null($number)) {
return 0;
} elseif (is_bool($number)) {
return (int) $number;
}
if (is_numeric($number)) {
return (int) floor($number);
}
@ -681,12 +686,15 @@ class PHPExcel_Calculation_MathTrig {
$y = PHPExcel_Calculation_Functions::flattenSingleValue($y);
// Validate parameters
if ($x == 0 && $y <= 0) {
if ($x == 0.0 && $y == 0.0) {
return PHPExcel_Calculation_Functions::NaN();
} elseif ($x == 0.0 && $y < 0.0) {
return PHPExcel_Calculation_Functions::DIV0();
}
// Return
return pow($x, $y);
$result = pow($x, $y);
return (!is_nan($result) && !is_infinite($result)) ? $result : PHPExcel_Calculation_Functions::NaN();
} // function POWER()
@ -915,6 +923,8 @@ class PHPExcel_Calculation_MathTrig {
public static function SIGN($number) {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
if (is_bool($number))
return (int) $number;
if (is_numeric($number)) {
if ($number == 0.0) {
return 0;

View File

@ -283,7 +283,7 @@ class PHPExcel_Cell
$result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog);
// echo $this->getCoordinate().' calculation result is '.$result.'<br />';
} catch ( Exception $ex ) {
if (($ex->getMessage() === 'Unable to access External Workbook') && (!is_null($this->_calculatedValue))) {
if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->_calculatedValue !== NULL)) {
// echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().'<br />';
return $this->_calculatedValue; // Fallback for calculations referencing external files.
}
@ -300,7 +300,7 @@ class PHPExcel_Cell
return $result;
}
// if (is_null($this->_value)) {
// if ($this->_value === NULL) {
// echo 'Cell '.$this->getCoordinate().' has no value, formula or otherwise<br />';
// return null;
// }
@ -813,7 +813,7 @@ class PHPExcel_Cell
* @return PHPExcel_Cell_IValueBinder
*/
public static function getValueBinder() {
if (is_null(self::$_valueBinder)) {
if (self::$_valueBinder === NULL) {
self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
}
@ -827,7 +827,7 @@ class PHPExcel_Cell
* @throws Exception
*/
public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = null) {
if (is_null($binder)) {
if ($binder === NULL) {
throw new Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
}

View File

@ -57,7 +57,7 @@ class PHPExcel_HashTable
*/
public function __construct($pSource = null)
{
if (!is_null($pSource)) {
if ($pSource !== NULL) {
// Create HashTable
$this->addFromSource($pSource);
}

View File

@ -612,7 +612,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
}
$cellRange = $columnID.$rowID;
if (!is_null($this->getReadFilter())) {
if ($this->getReadFilter() !== NULL) {
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
continue;
}

View File

@ -493,7 +493,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if ($xmlStyles && $xmlStyles->numFmts[0]) {
$numFmts = $xmlStyles->numFmts[0];
}
if (isset($numFmts) && !is_null($numFmts)) {
if (isset($numFmts) && ($numFmts !== NULL)) {
$numFmts->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
}
if (!$this->_readDataOnly && $xmlStyles) {
@ -793,7 +793,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$calculatedValue = null;
// Read cell?
if (!is_null($this->getReadFilter())) {
if ($this->getReadFilter() !== NULL) {
$coordinates = PHPExcel_Cell::coordinateFromString($r);
if (!$this->getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) {
@ -888,7 +888,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} else {
$cell->setValue($value);
}
if (!is_null($calculatedValue)) {
if ($calculatedValue !== NULL) {
$cell->setCalculatedValue($calculatedValue);
}
@ -1198,7 +1198,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
}
if (!is_null($column) && !is_null($row)) {
if (($column !== NULL) && ($row !== NULL)) {
// Set comment properties
$comment = $docSheet->getCommentByColumnAndRow($column, $row + 1);
$comment->getFillColor()->setRGB( $fillColor );
@ -1501,7 +1501,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$extractedRange = isset($range[1]) ? $range[1] : $range[0];
}
if (!is_null($locatedSheet)) {
if ($locatedSheet !== NULL) {
$excel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $locatedSheet, $extractedRange, false) );
}
}
@ -1540,7 +1540,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} else if (isset($color["indexed"])) {
return PHPExcel_Style_Color::indexedColor($color["indexed"],$background)->getARGB();
} else if (isset($color["theme"])) {
if (!is_null(self::$_theme)) {
if (self::$_theme !== NULL) {
$returnColour = self::$_theme->getColourByIndex((int)$color["theme"]);
if (isset($color["tint"])) {
$tintAdjust = (float) $color["tint"];

View File

@ -942,7 +942,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
if ($this->_version == self::XLS_BIFF8) {
foreach ($this->_sharedFormulaParts as $cell => $baseCell) {
list($column, $row) = PHPExcel_Cell::coordinateFromString($cell);
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle()) ) {
$formula = $this->_getFormulaFromStructure($this->_sharedFormulas[$baseCell], $cell);
$this->_phpSheet->getCell($cell)->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
}
@ -3307,7 +3307,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
// offset: 4; size: 2; index to XF record
$xfIndex = self::_GetInt2d($recordData, 4);
@ -3351,7 +3351,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
// offset: 4; size: 2; index to XF record
$xfIndex = self::_GetInt2d($recordData, 4);
@ -3437,7 +3437,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($colFirst + $i);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
// offset: var; size: 2; index to XF record
$xfIndex = self::_GetInt2d($recordData, $offset);
@ -3482,7 +3482,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
// offset 4; size: 2; index to XF record
$xfIndex = self::_GetInt2d($recordData, 4);
@ -3548,7 +3548,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
}
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if ($isPartOfSharedFormula) {
// formula is added to this cell after the sheet has been read
@ -3722,7 +3722,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
// offset: 4; size: 2; index to XF record
$xfIndex = self::_GetInt2d($recordData, 4);
@ -3785,7 +3785,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($fc + $i);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
$xfIndex = self::_GetInt2d($recordData, 4 + 2 * $i);
$this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
}
@ -3821,7 +3821,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
// offset: 4; size: 2; XF index
$xfIndex = self::_GetInt2d($recordData, 4);
@ -3863,7 +3863,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$columnString = PHPExcel_Cell::stringFromColumnIndex($col);
// Read cell?
if ( !is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
// offset: 4; size: 2; XF index
$xfIndex = self::_GetInt2d($recordData, 4);
@ -4069,7 +4069,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
private function _includeCellRangeFiltered($cellRangeAddress)
{
$includeCellRange = true;
if (!is_null($this->getReadFilter())) {
if ($this->getReadFilter() !== NULL) {
$includeCellRange = false;
$rangeBoundaries = PHPExcel_Cell::getRangeBoundaries($cellRangeAddress);
$rangeBoundaries[1][0]++;

View File

@ -464,7 +464,7 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
$column = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if (!is_null($this->getReadFilter())) {
if ($this->getReadFilter() !== NULL) {
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
continue;
}

View File

@ -414,7 +414,7 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
case 'table-row' :
$columnID = 'A';
foreach($rowData as $key => $cellData) {
if (!is_null($this->getReadFilter())) {
if ($this->getReadFilter() !== NULL) {
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
continue;
}

View File

@ -55,7 +55,7 @@ class PHPExcel_ReferenceHelper
* @return PHPExcel_ReferenceHelper
*/
public static function getInstance() {
if (!isset(self::$_instance) || is_null(self::$_instance)) {
if (!isset(self::$_instance) || (self::$_instance === NULL)) {
self::$_instance = new PHPExcel_ReferenceHelper();
}
@ -530,7 +530,7 @@ class PHPExcel_ReferenceHelper
foreach ($pPhpExcel->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
if (!is_null($cell) && $cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
if (($cell !== NULL) && ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA)) {
$formula = $cell->getValue();
if (strpos($formula, $oldName) !== false) {
$formula = str_replace("'" . $oldName . "'!", "'" . $newName . "'!", $formula);

View File

@ -703,4 +703,18 @@ class PHPExcel_Shared_String
return $pValue;
}
/**
* Retrieve any leading numeric part of a string, or return the full string if no leading numeric
* (handles basic integer or float, but not exponent or non decimal)
*
* @param string $value
* @return mixed string or only the leading numeric part of the string
*/
public static function testStringAsNumeric($value)
{
if (is_numeric($value))
return $value;
$v = floatval($value);
return (is_numeric(substr($value,0,strlen($v)))) ? $v : $value;
}
}

View File

@ -421,7 +421,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Re-order cell collection
return $this->sortCellCollection();
}
if (!is_null($this->_cellCollection)) {
if ($this->_cellCollection !== NULL) {
return $this->_cellCollection->getCellList();
}
return array();
@ -434,7 +434,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*/
public function sortCellCollection()
{
if (!is_null($this->_cellCollection)) {
if ($this->_cellCollection !== NULL) {
return $this->_cellCollection->getSortedCellList();
}
return array();
@ -984,7 +984,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
(preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
$namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
if (!is_null($namedRange)) {
if ($namedRange !== NULL) {
$pCoordinate = $namedRange->getRange();
return $namedRange->getWorksheet()->getCell($pCoordinate);
}

View File

@ -222,7 +222,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
*/
private function _mapBorderStyle($borderStyle) {
switch ($borderStyle) {
case PHPExcel_Style_Border::BORDER_NONE: return '0px';
case PHPExcel_Style_Border::BORDER_NONE: return '1px hidden';
case PHPExcel_Style_Border::BORDER_DASHDOT: return '1px dashed';
case PHPExcel_Style_Border::BORDER_DASHDOTDOT: return '1px dotted';
case PHPExcel_Style_Border::BORDER_DASHED: return '1px dashed';
@ -839,11 +839,8 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
* @return string
*/
private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle) {
// Construct HTML
$css = '';
// Create CSS
$css .= $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
$css = $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
// Return
return $css;