From 547d2bd3b24cf4c6207f9b086dd2c64390ecf571 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 11 May 2015 01:31:26 +0100 Subject: [PATCH] More PSR-2 --- Classes/PHPExcel/Calculation/Database.php | 2 +- Classes/PHPExcel/Calculation/Functions.php | 30 +- Classes/PHPExcel/Calculation/MathTrig.php | 2 +- Classes/PHPExcel/Calculation/Statistical.php | 44 +- Classes/PHPExcel/Cell.php | 1706 +++++++++--------- 5 files changed, 888 insertions(+), 896 deletions(-) diff --git a/Classes/PHPExcel/Calculation/Database.php b/Classes/PHPExcel/Calculation/Database.php index 9afcffd4..af150fe0 100644 --- a/Classes/PHPExcel/Calculation/Database.php +++ b/Classes/PHPExcel/Calculation/Database.php @@ -99,7 +99,7 @@ class PHPExcel_Calculation_Database $testConditionCount = 0; foreach ($criteria as $row => $criterion) { if ($criterion[$key] > '') { - $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]); + $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::ifCondition($criterion[$key]); $testConditionCount++; } } diff --git a/Classes/PHPExcel/Calculation/Functions.php b/Classes/PHPExcel/Calculation/Functions.php index b10f242c..4d1771b9 100644 --- a/Classes/PHPExcel/Calculation/Functions.php +++ b/Classes/PHPExcel/Calculation/Functions.php @@ -67,7 +67,7 @@ class PHPExcel_Calculation_Functions * @access private * @var string */ - protected static $compatibilityMode = self::COMPATIBILITY_EXCEL; + protected static $compatibilityMode = self::COMPATIBILITY_EXCEL; /** * Data Type to use when returning date values @@ -75,7 +75,7 @@ class PHPExcel_Calculation_Functions * @access private * @var string */ - protected static $ReturnDateType = self::RETURNDATE_EXCEL; + protected static $returnDateType = self::RETURNDATE_EXCEL; /** * List of error codes @@ -83,7 +83,7 @@ class PHPExcel_Calculation_Functions * @access private * @var array */ - protected static $_errorCodes = array( + protected static $errorCodes = array( 'null' => '#NULL!', 'divisionbyzero' => '#DIV/0!', 'value' => '#VALUE!', @@ -153,7 +153,7 @@ class PHPExcel_Calculation_Functions if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) || ($returnDateType == self::RETURNDATE_PHP_OBJECT) || ($returnDateType == self::RETURNDATE_EXCEL)) { - self::$ReturnDateType = $returnDateType; + self::$returnDateType = $returnDateType; return true; } return false; @@ -173,7 +173,7 @@ class PHPExcel_Calculation_Functions */ public static function getReturnDateType() { - return self::$ReturnDateType; + return self::$returnDateType; } @@ -199,7 +199,7 @@ class PHPExcel_Calculation_Functions */ public static function DIV0() { - return self::$_errorCodes['divisionbyzero']; + return self::$errorCodes['divisionbyzero']; } @@ -218,7 +218,7 @@ class PHPExcel_Calculation_Functions */ public static function NA() { - return self::$_errorCodes['na']; + return self::$errorCodes['na']; } @@ -233,7 +233,7 @@ class PHPExcel_Calculation_Functions */ public static function NaN() { - return self::$_errorCodes['num']; + return self::$errorCodes['num']; } @@ -248,7 +248,7 @@ class PHPExcel_Calculation_Functions */ public static function NAME() { - return self::$_errorCodes['name']; + return self::$errorCodes['name']; } @@ -263,7 +263,7 @@ class PHPExcel_Calculation_Functions */ public static function REF() { - return self::$_errorCodes['reference']; + return self::$errorCodes['reference']; } @@ -278,7 +278,7 @@ class PHPExcel_Calculation_Functions */ public static function NULL() { - return self::$_errorCodes['null']; + return self::$errorCodes['null']; } @@ -293,7 +293,7 @@ class PHPExcel_Calculation_Functions */ public static function VALUE() { - return self::$_errorCodes['value']; + return self::$errorCodes['value']; } @@ -315,7 +315,7 @@ class PHPExcel_Calculation_Functions } - public static function _ifCondition($condition) + public static function ifCondition($condition) { $condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition); if (!isset($condition{0})) { @@ -350,7 +350,7 @@ class PHPExcel_Calculation_Functions $value = self::flattenSingleValue($value); $i = 1; - foreach (self::$_errorCodes as $errorCode) { + foreach (self::$errorCodes as $errorCode) { if ($value === $errorCode) { return $i; } @@ -403,7 +403,7 @@ class PHPExcel_Calculation_Functions if (!is_string($value)) { return false; } - return in_array($value, array_values(self::$_errorCodes)); + return in_array($value, array_values(self::$errorCodes)); } diff --git a/Classes/PHPExcel/Calculation/MathTrig.php b/Classes/PHPExcel/Calculation/MathTrig.php index df0c88b8..d062d032 100644 --- a/Classes/PHPExcel/Calculation/MathTrig.php +++ b/Classes/PHPExcel/Calculation/MathTrig.php @@ -1201,7 +1201,7 @@ class PHPExcel_Calculation_MathTrig if (empty($sumArgs)) { $sumArgs = $aArgs; } - $condition = PHPExcel_Calculation_Functions::_ifCondition($condition); + $condition = PHPExcel_Calculation_Functions::ifCondition($condition); // Loop through arguments foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { diff --git a/Classes/PHPExcel/Calculation/Statistical.php b/Classes/PHPExcel/Calculation/Statistical.php index ad523f67..11e54a5e 100644 --- a/Classes/PHPExcel/Calculation/Statistical.php +++ b/Classes/PHPExcel/Calculation/Statistical.php @@ -91,12 +91,12 @@ class PHPExcel_Calculation_Statistical * @param q require q>0 * @return 0 if p<=0, q<=0 or p+q>2.55E305 to avoid errors and over/underflow */ - private static function _beta($p, $q) + private static function beta($p, $q) { if ($p <= 0.0 || $q <= 0.0 || ($p + $q) > LOG_GAMMA_X_MAX_VALUE) { return 0.0; } else { - return exp(self::_logBeta($p, $q)); + return exp(self::logBeta($p, $q)); } } @@ -113,7 +113,7 @@ class PHPExcel_Calculation_Statistical * @param q require q>0 * @return 0 if x<0, p<=0, q<=0 or p+q>2.55E305 and 1 if x>1 to avoid errors and over/underflow */ - private static function _incompleteBeta($x, $p, $q) + private static function incompleteBeta($x, $p, $q) { if ($x <= 0.0) { return 0.0; @@ -122,16 +122,16 @@ class PHPExcel_Calculation_Statistical } elseif (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) { return 0.0; } - $beta_gam = exp((0 - self::_logBeta($p, $q)) + $p * log($x) + $q * log(1.0 - $x)); + $beta_gam = exp((0 - self::logBeta($p, $q)) + $p * log($x) + $q * log(1.0 - $x)); if ($x < ($p + 1.0) / ($p + $q + 2.0)) { - return $beta_gam * self::_betaFraction($x, $p, $q) / $p; + return $beta_gam * self::betaFraction($x, $p, $q) / $p; } else { - return 1.0 - ($beta_gam * self::_betaFraction(1 - $x, $q, $p) / $q); + return 1.0 - ($beta_gam * self::betaFraction(1 - $x, $q, $p) / $q); } } - // Function cache for _logBeta function + // Function cache for logBeta function private static $logBetaCacheP = 0.0; private static $logBetaCacheQ = 0.0; private static $logBetaCacheResult = 0.0; @@ -144,7 +144,7 @@ class PHPExcel_Calculation_Statistical * @return 0 if p<=0, q<=0 or p+q>2.55E305 to avoid errors and over/underflow * @author Jaco van Kooten */ - private static function _logBeta($p, $q) + private static function logBeta($p, $q) { if ($p != self::$logBetaCacheP || $q != self::$logBetaCacheQ) { self::$logBetaCacheP = $p; @@ -152,7 +152,7 @@ class PHPExcel_Calculation_Statistical if (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) { self::$logBetaCacheResult = 0.0; } else { - self::$logBetaCacheResult = self::_logGamma($p) + self::_logGamma($q) - self::_logGamma($p + $q); + self::$logBetaCacheResult = self::logGamma($p) + self::logGamma($q) - self::logGamma($p + $q); } } return self::$logBetaCacheResult; @@ -164,7 +164,7 @@ class PHPExcel_Calculation_Statistical * Based on an idea from Numerical Recipes (W.H. Press et al, 1992). * @author Jaco van Kooten */ - private static function _betaFraction($x, $p, $q) + private static function betaFraction($x, $p, $q) { $c = 1.0; $sum_pq = $p + $q; @@ -258,7 +258,7 @@ class PHPExcel_Calculation_Statistical private static $logGammaCacheResult = 0.0; private static $logGammaCacheX = 0.0; - private static function _logGamma($x) + private static function logGamma($x) { // Log Gamma related constants static $lg_d1 = -0.5772156649015328605195174; @@ -435,7 +435,7 @@ class PHPExcel_Calculation_Statistical // // Private implementation of the incomplete Gamma function // - private static function _incompleteGamma($a, $x) + private static function incompleteGamma($a, $x) { static $max = 32; $summer = 0; @@ -453,7 +453,7 @@ class PHPExcel_Calculation_Statistical // // Private implementation of the Gamma function // - private static function _gamma($data) + private static function gamma($data) { if ($data == 0.0) { return 0; @@ -872,7 +872,7 @@ class PHPExcel_Calculation_Statistical if (empty($averageArgs)) { $averageArgs = $aArgs; } - $condition = PHPExcel_Calculation_Functions::_ifCondition($condition); + $condition = PHPExcel_Calculation_Functions::ifCondition($condition); // Loop through arguments $aCount = 0; foreach ($aArgs as $key => $arg) { @@ -926,7 +926,7 @@ class PHPExcel_Calculation_Statistical } $value -= $rMin; $value /= ($rMax - $rMin); - return self::_incompleteBeta($value, $alpha, $beta); + return self::incompleteBeta($value, $alpha, $beta); } return PHPExcel_Calculation_Functions::VALUE(); } @@ -1058,7 +1058,7 @@ class PHPExcel_Calculation_Statistical } return PHPExcel_Calculation_Functions::NaN(); } - return 1 - (self::_incompleteGamma($degrees/2, $value/2) / self::_gamma($degrees/2)); + return 1 - (self::incompleteGamma($degrees/2, $value/2) / self::gamma($degrees/2)); } return PHPExcel_Calculation_Functions::VALUE(); } @@ -1294,7 +1294,7 @@ class PHPExcel_Calculation_Statistical $returnValue = 0; $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); - $condition = PHPExcel_Calculation_Functions::_ifCondition($condition); + $condition = PHPExcel_Calculation_Functions::ifCondition($condition); // Loop through arguments foreach ($aArgs as $arg) { if (!is_numeric($arg)) { @@ -1649,9 +1649,9 @@ class PHPExcel_Calculation_Statistical } if ((is_numeric($cumulative)) || (is_bool($cumulative))) { if ($cumulative) { - return self::_incompleteGamma($a, $value / $b) / self::_gamma($a); + return self::incompleteGamma($a, $value / $b) / self::gamma($a); } else { - return (1 / (pow($b, $a) * self::_gamma($a))) * pow($value, $a-1) * exp(0-($value / $b)); + return (1 / (pow($b, $a) * self::gamma($a))) * pow($value, $a-1) * exp(0-($value / $b)); } } } @@ -1737,7 +1737,7 @@ class PHPExcel_Calculation_Statistical if ($value <= 0) { return PHPExcel_Calculation_Functions::NaN(); } - return log(self::_gamma($value)); + return log(self::gamma($value)); } return PHPExcel_Calculation_Functions::VALUE(); } @@ -2286,7 +2286,7 @@ class PHPExcel_Calculation_Statistical if (empty($sumArgs)) { $sumArgs = $aArgs; } - $condition = PHPExcel_Calculation_Functions::_ifCondition($condition); + $condition = PHPExcel_Calculation_Functions::ifCondition($condition); // Loop through arguments foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { @@ -2445,7 +2445,7 @@ class PHPExcel_Calculation_Statistical if (empty($sumArgs)) { $sumArgs = $aArgs; } - $condition = PHPExcel_Calculation_Functions::_ifCondition($condition); + $condition = PHPExcel_Calculation_Functions::ifCondition($condition); // Loop through arguments foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { diff --git a/Classes/PHPExcel/Cell.php b/Classes/PHPExcel/Cell.php index ae5b557d..4e1c863c 100644 --- a/Classes/PHPExcel/Cell.php +++ b/Classes/PHPExcel/Cell.php @@ -1,369 +1,361 @@ _parent->updateCacheData($this); + /** + * Send notification to the cache controller + * + * @return void + **/ + public function notifyCacheController() { + $this->_parent->updateCacheData($this); - return $this; - } + return $this; + } - public function detach() { - $this->_parent = NULL; - } + public function detach() { + $this->_parent = NULL; + } - public function attach(PHPExcel_CachedObjectStorage_CacheBase $parent) { - $this->_parent = $parent; - } + public function attach(PHPExcel_CachedObjectStorage_CacheBase $parent) { + $this->_parent = $parent; + } - /** - * Create a new Cell - * - * @param mixed $pValue - * @param string $pDataType - * @param PHPExcel_Worksheet $pSheet - * @throws PHPExcel_Exception - */ - public function __construct($pValue = NULL, $pDataType = NULL, PHPExcel_Worksheet $pSheet = NULL) - { - // Initialise cell value - $this->_value = $pValue; + /** + * Create a new Cell + * + * @param mixed $pValue + * @param string $pDataType + * @param PHPExcel_Worksheet $pSheet + * @throws PHPExcel_Exception + */ + public function __construct($pValue = NULL, $pDataType = NULL, PHPExcel_Worksheet $pSheet = NULL) + { + // Initialise cell value + $this->_value = $pValue; - // Set worksheet cache - $this->_parent = $pSheet->getCellCacheController(); + // Set worksheet cache + $this->_parent = $pSheet->getCellCacheController(); - // Set datatype? - if ($pDataType !== NULL) { - if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2) - $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; - $this->_dataType = $pDataType; - } elseif (!self::getValueBinder()->bindValue($this, $pValue)) { + // Set datatype? + if ($pDataType !== NULL) { + if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2) + $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; + $this->_dataType = $pDataType; + } elseif (!self::getValueBinder()->bindValue($this, $pValue)) { throw new PHPExcel_Exception("Value could not be bound to cell."); - } - } + } + } - /** - * Get cell coordinate column - * - * @return string - */ - public function getColumn() - { - return $this->_parent->getCurrentColumn(); - } + /** + * Get cell coordinate column + * + * @return string + */ + public function getColumn() + { + return $this->_parent->getCurrentColumn(); + } - /** - * Get cell coordinate row - * - * @return int - */ - public function getRow() - { - return $this->_parent->getCurrentRow(); - } + /** + * Get cell coordinate row + * + * @return int + */ + public function getRow() + { + return $this->_parent->getCurrentRow(); + } - /** - * Get cell coordinate - * - * @return string - */ - public function getCoordinate() - { - return $this->_parent->getCurrentAddress(); - } + /** + * Get cell coordinate + * + * @return string + */ + public function getCoordinate() + { + return $this->_parent->getCurrentAddress(); + } - /** - * Get cell value - * - * @return mixed - */ - public function getValue() - { - return $this->_value; - } + /** + * Get cell value + * + * @return mixed + */ + public function getValue() + { + return $this->_value; + } - /** - * Get cell value with formatting - * - * @return string - */ - public function getFormattedValue() - { - return (string) PHPExcel_Style_NumberFormat::toFormattedString( - $this->getCalculatedValue(), - $this->getStyle() - ->getNumberFormat()->getFormatCode() - ); - } + /** + * Get cell value with formatting + * + * @return string + */ + public function getFormattedValue() + { + return (string) PHPExcel_Style_NumberFormat::toFormattedString( + $this->getCalculatedValue(), + $this->getStyle() + ->getNumberFormat()->getFormatCode() + ); + } - /** - * Set cell value - * - * Sets the value for a cell, automatically determining the datatype using the value binder - * - * @param mixed $pValue Value - * @return PHPExcel_Cell - * @throws PHPExcel_Exception - */ - public function setValue($pValue = NULL) - { - if (!self::getValueBinder()->bindValue($this, $pValue)) { - throw new PHPExcel_Exception("Value could not be bound to cell."); - } - return $this; - } + /** + * Set cell value + * + * Sets the value for a cell, automatically determining the datatype using the value binder + * + * @param mixed $pValue Value + * @return PHPExcel_Cell + * @throws PHPExcel_Exception + */ + public function setValue($pValue = NULL) + { + if (!self::getValueBinder()->bindValue($this, $pValue)) { + throw new PHPExcel_Exception("Value could not be bound to cell."); + } + return $this; + } - /** - * Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder) - * - * @param mixed $pValue Value - * @param string $pDataType Explicit data type - * @return PHPExcel_Cell - * @throws PHPExcel_Exception - */ - public function setValueExplicit($pValue = NULL, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING) - { - // set the value according to data type - switch ($pDataType) { - case PHPExcel_Cell_DataType::TYPE_NULL: - $this->_value = $pValue; - break; - case PHPExcel_Cell_DataType::TYPE_STRING2: - $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; - case PHPExcel_Cell_DataType::TYPE_STRING: - case PHPExcel_Cell_DataType::TYPE_INLINE: - $this->_value = PHPExcel_Cell_DataType::checkString($pValue); - break; - case PHPExcel_Cell_DataType::TYPE_NUMERIC: - $this->_value = (float)$pValue; - break; - case PHPExcel_Cell_DataType::TYPE_FORMULA: - $this->_value = (string)$pValue; - break; - case PHPExcel_Cell_DataType::TYPE_BOOL: - $this->_value = (bool)$pValue; - break; - case PHPExcel_Cell_DataType::TYPE_ERROR: - $this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue); - break; - default: - throw new PHPExcel_Exception('Invalid datatype: ' . $pDataType); - break; - } + /** + * Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder) + * + * @param mixed $pValue Value + * @param string $pDataType Explicit data type + * @return PHPExcel_Cell + * @throws PHPExcel_Exception + */ + public function setValueExplicit($pValue = NULL, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING) + { + // set the value according to data type + switch ($pDataType) { + case PHPExcel_Cell_DataType::TYPE_NULL: + $this->_value = $pValue; + break; + case PHPExcel_Cell_DataType::TYPE_STRING2: + $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; + case PHPExcel_Cell_DataType::TYPE_STRING: + case PHPExcel_Cell_DataType::TYPE_INLINE: + $this->_value = PHPExcel_Cell_DataType::checkString($pValue); + break; + case PHPExcel_Cell_DataType::TYPE_NUMERIC: + $this->_value = (float)$pValue; + break; + case PHPExcel_Cell_DataType::TYPE_FORMULA: + $this->_value = (string)$pValue; + break; + case PHPExcel_Cell_DataType::TYPE_BOOL: + $this->_value = (bool)$pValue; + break; + case PHPExcel_Cell_DataType::TYPE_ERROR: + $this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue); + break; + default: + throw new PHPExcel_Exception('Invalid datatype: ' . $pDataType); + break; + } - // set the datatype - $this->_dataType = $pDataType; + // set the datatype + $this->_dataType = $pDataType; - return $this->notifyCacheController(); - } + return $this->notifyCacheController(); + } - /** - * Get calculated cell value - * - * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling - * - * @param boolean $resetLog Whether the calculation engine logger should be reset or not - * @return mixed - * @throws PHPExcel_Exception - */ - public function getCalculatedValue($resetLog = TRUE) - { + /** + * Get calculated cell value + * + * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling + * + * @param boolean $resetLog Whether the calculation engine logger should be reset or not + * @return mixed + * @throws PHPExcel_Exception + */ + public function getCalculatedValue($resetLog = TRUE) + { //echo 'Cell '.$this->getCoordinate().' value is a '.$this->_dataType.' with a value of '.$this->getValue().PHP_EOL; - if ($this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) { - try { + if ($this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) { + try { //echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value'.PHP_EOL; - $result = PHPExcel_Calculation::getInstance( - $this->getWorksheet()->getParent() - )->calculateCellValue($this,$resetLog); + $result = PHPExcel_Calculation::getInstance( + $this->getWorksheet()->getParent() + )->calculateCellValue($this,$resetLog); //echo $this->getCoordinate().' calculation result is '.$result.PHP_EOL; - // We don't yet handle array returns - if (is_array($result)) { - while (is_array($result)) { - $result = array_pop($result); - } - } - } catch ( PHPExcel_Exception $ex ) { - if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->_calculatedValue !== NULL)) { + // We don't yet handle array returns + if (is_array($result)) { + while (is_array($result)) { + $result = array_pop($result); + } + } + } catch ( PHPExcel_Exception $ex ) { + if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->_calculatedValue !== NULL)) { //echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL; - return $this->_calculatedValue; // Fallback for calculations referencing external files. - } + return $this->_calculatedValue; // Fallback for calculations referencing external files. + } //echo 'Calculation Exception: '.$ex->getMessage().PHP_EOL; - $result = '#N/A'; - throw new PHPExcel_Calculation_Exception( - $this->getWorksheet()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage() - ); - } + $result = '#N/A'; + throw new PHPExcel_Calculation_Exception( + $this->getWorksheet()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage() + ); + } - if ($result === '#Not Yet Implemented') { + if ($result === '#Not Yet Implemented') { //echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL; - return $this->_calculatedValue; // Fallback if calculation engine does not support the formula. - } + return $this->_calculatedValue; // Fallback if calculation engine does not support the formula. + } //echo 'Returning calculated value of '.$result.' for cell '.$this->getCoordinate().PHP_EOL; - return $result; - } elseif($this->_value instanceof PHPExcel_RichText) { -// echo 'Cell value for '.$this->getCoordinate().' is rich text: Returning data value of '.$this->_value.'
'; - return $this->_value->getPlainText(); - } -// echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'
'; - return $this->_value; - } + return $result; + } elseif($this->_value instanceof PHPExcel_RichText) { +// echo 'Cell value for '.$this->getCoordinate().' is rich text: Returning data value of '.$this->_value.'
'; + return $this->_value->getPlainText(); + } +// echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'
'; + return $this->_value; + } - /** - * Set old calculated value (cached) - * - * @param mixed $pValue Value - * @return PHPExcel_Cell - */ - public function setCalculatedValue($pValue = NULL) - { - if ($pValue !== NULL) { - $this->_calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue; - } + /** + * Set old calculated value (cached) + * + * @param mixed $pValue Value + * @return PHPExcel_Cell + */ + public function setCalculatedValue($pValue = NULL) + { + if ($pValue !== NULL) { + $this->_calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue; + } - return $this->notifyCacheController(); - } + return $this->notifyCacheController(); + } - /** - * Get old calculated value (cached) - * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to - * create the original spreadsheet file. - * Note that this value is not guaranteed to refelect the actual calculated value because it is - * possible that auto-calculation was disabled in the original spreadsheet, and underlying data - * values used by the formula have changed since it was last calculated. - * - * @return mixed - */ - public function getOldCalculatedValue() - { - return $this->_calculatedValue; - } + /** + * Get old calculated value (cached) + * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to + * create the original spreadsheet file. + * Note that this value is not guaranteed to refelect the actual calculated value because it is + * possible that auto-calculation was disabled in the original spreadsheet, and underlying data + * values used by the formula have changed since it was last calculated. + * + * @return mixed + */ + public function getOldCalculatedValue() + { + return $this->_calculatedValue; + } - /** - * Get cell data type - * - * @return string - */ - public function getDataType() - { - return $this->_dataType; - } + /** + * Get cell data type + * + * @return string + */ + public function getDataType() + { + return $this->_dataType; + } - /** - * Set cell data type - * - * @param string $pDataType - * @return PHPExcel_Cell - */ - public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING) - { - if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2) - $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; + /** + * Set cell data type + * + * @param string $pDataType + * @return PHPExcel_Cell + */ + public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING) + { + if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2) + $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; - $this->_dataType = $pDataType; + $this->_dataType = $pDataType; - return $this->notifyCacheController(); - } + return $this->notifyCacheController(); + } /** * Identify if the cell contains a formula @@ -375,134 +367,134 @@ class PHPExcel_Cell return $this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA; } - /** - * Does this cell contain Data validation rules? - * - * @return boolean - * @throws PHPExcel_Exception - */ - public function hasDataValidation() - { - if (!isset($this->_parent)) { - throw new PHPExcel_Exception('Cannot check for data validation when cell is not bound to a worksheet'); - } + /** + * Does this cell contain Data validation rules? + * + * @return boolean + * @throws PHPExcel_Exception + */ + public function hasDataValidation() + { + if (!isset($this->_parent)) { + throw new PHPExcel_Exception('Cannot check for data validation when cell is not bound to a worksheet'); + } - return $this->getWorksheet()->dataValidationExists($this->getCoordinate()); - } + return $this->getWorksheet()->dataValidationExists($this->getCoordinate()); + } - /** - * Get Data validation rules - * - * @return PHPExcel_Cell_DataValidation - * @throws PHPExcel_Exception - */ - public function getDataValidation() - { - if (!isset($this->_parent)) { - throw new PHPExcel_Exception('Cannot get data validation for cell that is not bound to a worksheet'); - } + /** + * Get Data validation rules + * + * @return PHPExcel_Cell_DataValidation + * @throws PHPExcel_Exception + */ + public function getDataValidation() + { + if (!isset($this->_parent)) { + throw new PHPExcel_Exception('Cannot get data validation for cell that is not bound to a worksheet'); + } - return $this->getWorksheet()->getDataValidation($this->getCoordinate()); - } + return $this->getWorksheet()->getDataValidation($this->getCoordinate()); + } - /** - * Set Data validation rules - * - * @param PHPExcel_Cell_DataValidation $pDataValidation - * @return PHPExcel_Cell - * @throws PHPExcel_Exception - */ - public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = NULL) - { - if (!isset($this->_parent)) { - throw new PHPExcel_Exception('Cannot set data validation for cell that is not bound to a worksheet'); - } + /** + * Set Data validation rules + * + * @param PHPExcel_Cell_DataValidation $pDataValidation + * @return PHPExcel_Cell + * @throws PHPExcel_Exception + */ + public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = NULL) + { + if (!isset($this->_parent)) { + throw new PHPExcel_Exception('Cannot set data validation for cell that is not bound to a worksheet'); + } - $this->getWorksheet()->setDataValidation($this->getCoordinate(), $pDataValidation); + $this->getWorksheet()->setDataValidation($this->getCoordinate(), $pDataValidation); - return $this->notifyCacheController(); - } + return $this->notifyCacheController(); + } - /** - * Does this cell contain a Hyperlink? - * - * @return boolean - * @throws PHPExcel_Exception - */ - public function hasHyperlink() - { - if (!isset($this->_parent)) { - throw new PHPExcel_Exception('Cannot check for hyperlink when cell is not bound to a worksheet'); - } + /** + * Does this cell contain a Hyperlink? + * + * @return boolean + * @throws PHPExcel_Exception + */ + public function hasHyperlink() + { + if (!isset($this->_parent)) { + throw new PHPExcel_Exception('Cannot check for hyperlink when cell is not bound to a worksheet'); + } - return $this->getWorksheet()->hyperlinkExists($this->getCoordinate()); - } + return $this->getWorksheet()->hyperlinkExists($this->getCoordinate()); + } - /** - * Get Hyperlink - * - * @return PHPExcel_Cell_Hyperlink - * @throws PHPExcel_Exception - */ - public function getHyperlink() - { - if (!isset($this->_parent)) { - throw new PHPExcel_Exception('Cannot get hyperlink for cell that is not bound to a worksheet'); - } + /** + * Get Hyperlink + * + * @return PHPExcel_Cell_Hyperlink + * @throws PHPExcel_Exception + */ + public function getHyperlink() + { + if (!isset($this->_parent)) { + throw new PHPExcel_Exception('Cannot get hyperlink for cell that is not bound to a worksheet'); + } - return $this->getWorksheet()->getHyperlink($this->getCoordinate()); - } + return $this->getWorksheet()->getHyperlink($this->getCoordinate()); + } - /** - * Set Hyperlink - * - * @param PHPExcel_Cell_Hyperlink $pHyperlink - * @return PHPExcel_Cell - * @throws PHPExcel_Exception - */ - public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = NULL) - { - if (!isset($this->_parent)) { - throw new PHPExcel_Exception('Cannot set hyperlink for cell that is not bound to a worksheet'); - } + /** + * Set Hyperlink + * + * @param PHPExcel_Cell_Hyperlink $pHyperlink + * @return PHPExcel_Cell + * @throws PHPExcel_Exception + */ + public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = NULL) + { + if (!isset($this->_parent)) { + throw new PHPExcel_Exception('Cannot set hyperlink for cell that is not bound to a worksheet'); + } - $this->getWorksheet()->setHyperlink($this->getCoordinate(), $pHyperlink); + $this->getWorksheet()->setHyperlink($this->getCoordinate(), $pHyperlink); - return $this->notifyCacheController(); - } + return $this->notifyCacheController(); + } - /** - * Get parent worksheet - * - * @return PHPExcel_CachedObjectStorage_CacheBase - */ - public function getParent() { - return $this->_parent; - } + /** + * Get parent worksheet + * + * @return PHPExcel_CachedObjectStorage_CacheBase + */ + public function getParent() { + return $this->_parent; + } - /** - * Get parent worksheet - * - * @return PHPExcel_Worksheet - */ - public function getWorksheet() { - return $this->_parent->getParent(); - } + /** + * Get parent worksheet + * + * @return PHPExcel_Worksheet + */ + public function getWorksheet() { + return $this->_parent->getParent(); + } - /** - * Is this cell in a merge range - * - * @return boolean - */ + /** + * Is this cell in a merge range + * + * @return boolean + */ public function isInMergeRange() { return (boolean) $this->getMergeRange(); } - /** - * Is this cell the master (top left cell) in a merge range (that holds the actual data value) - * - * @return boolean - */ + /** + * Is this cell the master (top left cell) in a merge range (that holds the actual data value) + * + * @return boolean + */ public function isMergeRangeValueCell() { if ($mergeRange = $this->getMergeRange()) { $mergeRange = PHPExcel_Cell::splitRange($mergeRange); @@ -514,11 +506,11 @@ class PHPExcel_Cell return false; } - /** - * If this cell is in a merge range, then return the range - * - * @return string - */ + /** + * If this cell is in a merge range, then return the range + * + * @return string + */ public function getMergeRange() { foreach($this->getWorksheet()->getMergeCells() as $mergeRange) { if ($this->isInRange($mergeRange)) { @@ -528,495 +520,495 @@ class PHPExcel_Cell return false; } - /** - * Get cell style - * - * @return PHPExcel_Style - */ - public function getStyle() - { - return $this->getWorksheet()->getStyle($this->getCoordinate()); - } + /** + * Get cell style + * + * @return PHPExcel_Style + */ + public function getStyle() + { + return $this->getWorksheet()->getStyle($this->getCoordinate()); + } - /** - * Re-bind parent - * - * @param PHPExcel_Worksheet $parent - * @return PHPExcel_Cell - */ - public function rebindParent(PHPExcel_Worksheet $parent) { - $this->_parent = $parent->getCellCacheController(); + /** + * Re-bind parent + * + * @param PHPExcel_Worksheet $parent + * @return PHPExcel_Cell + */ + public function rebindParent(PHPExcel_Worksheet $parent) { + $this->_parent = $parent->getCellCacheController(); - return $this->notifyCacheController(); - } + return $this->notifyCacheController(); + } - /** - * Is cell in a specific range? - * - * @param string $pRange Cell range (e.g. A1:A1) - * @return boolean - */ - public function isInRange($pRange = 'A1:A1') - { - list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange); + /** + * Is cell in a specific range? + * + * @param string $pRange Cell range (e.g. A1:A1) + * @return boolean + */ + public function isInRange($pRange = 'A1:A1') + { + list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange); - // Translate properties - $myColumn = self::columnIndexFromString($this->getColumn()); - $myRow = $this->getRow(); + // Translate properties + $myColumn = self::columnIndexFromString($this->getColumn()); + $myRow = $this->getRow(); - // Verify if cell is in range - return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) && - ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow) - ); - } + // Verify if cell is in range + return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) && + ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow) + ); + } - /** - * Coordinate from string - * - * @param string $pCoordinateString - * @return array Array containing column and row (indexes 0 and 1) - * @throws PHPExcel_Exception - */ - public static function coordinateFromString($pCoordinateString = 'A1') - { - if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) { - return array($matches[1],$matches[2]); - } elseif ((strpos($pCoordinateString,':') !== FALSE) || (strpos($pCoordinateString,',') !== FALSE)) { - throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells'); - } elseif ($pCoordinateString == '') { - throw new PHPExcel_Exception('Cell coordinate can not be zero-length string'); - } + /** + * Coordinate from string + * + * @param string $pCoordinateString + * @return array Array containing column and row (indexes 0 and 1) + * @throws PHPExcel_Exception + */ + public static function coordinateFromString($pCoordinateString = 'A1') + { + if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) { + return array($matches[1],$matches[2]); + } elseif ((strpos($pCoordinateString,':') !== FALSE) || (strpos($pCoordinateString,',') !== FALSE)) { + throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells'); + } elseif ($pCoordinateString == '') { + throw new PHPExcel_Exception('Cell coordinate can not be zero-length string'); + } - throw new PHPExcel_Exception('Invalid cell coordinate '.$pCoordinateString); - } + throw new PHPExcel_Exception('Invalid cell coordinate '.$pCoordinateString); + } - /** - * Make string row, column or cell coordinate absolute - * - * @param string $pCoordinateString e.g. 'A' or '1' or 'A1' - * Note that this value can be a row or column reference as well as a cell reference - * @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1' - * @throws PHPExcel_Exception - */ - public static function absoluteReference($pCoordinateString = 'A1') - { - if (strpos($pCoordinateString,':') === FALSE && strpos($pCoordinateString,',') === FALSE) { - // Split out any worksheet name from the reference - $worksheet = ''; - $cellAddress = explode('!',$pCoordinateString); - if (count($cellAddress) > 1) { - list($worksheet,$pCoordinateString) = $cellAddress; - } - if ($worksheet > '') $worksheet .= '!'; + /** + * Make string row, column or cell coordinate absolute + * + * @param string $pCoordinateString e.g. 'A' or '1' or 'A1' + * Note that this value can be a row or column reference as well as a cell reference + * @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1' + * @throws PHPExcel_Exception + */ + public static function absoluteReference($pCoordinateString = 'A1') + { + if (strpos($pCoordinateString,':') === FALSE && strpos($pCoordinateString,',') === FALSE) { + // Split out any worksheet name from the reference + $worksheet = ''; + $cellAddress = explode('!',$pCoordinateString); + if (count($cellAddress) > 1) { + list($worksheet,$pCoordinateString) = $cellAddress; + } + if ($worksheet > '') $worksheet .= '!'; - // Create absolute coordinate - if (ctype_digit($pCoordinateString)) { - return $worksheet . '$' . $pCoordinateString; - } elseif (ctype_alpha($pCoordinateString)) { - return $worksheet . '$' . strtoupper($pCoordinateString); - } - return $worksheet . self::absoluteCoordinate($pCoordinateString); - } + // Create absolute coordinate + if (ctype_digit($pCoordinateString)) { + return $worksheet . '$' . $pCoordinateString; + } elseif (ctype_alpha($pCoordinateString)) { + return $worksheet . '$' . strtoupper($pCoordinateString); + } + return $worksheet . self::absoluteCoordinate($pCoordinateString); + } - throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells'); - } + throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells'); + } - /** - * Make string coordinate absolute - * - * @param string $pCoordinateString e.g. 'A1' - * @return string Absolute coordinate e.g. '$A$1' - * @throws PHPExcel_Exception - */ - public static function absoluteCoordinate($pCoordinateString = 'A1') - { - if (strpos($pCoordinateString,':') === FALSE && strpos($pCoordinateString,',') === FALSE) { - // Split out any worksheet name from the coordinate - $worksheet = ''; - $cellAddress = explode('!',$pCoordinateString); - if (count($cellAddress) > 1) { - list($worksheet,$pCoordinateString) = $cellAddress; - } - if ($worksheet > '') $worksheet .= '!'; + /** + * Make string coordinate absolute + * + * @param string $pCoordinateString e.g. 'A1' + * @return string Absolute coordinate e.g. '$A$1' + * @throws PHPExcel_Exception + */ + public static function absoluteCoordinate($pCoordinateString = 'A1') + { + if (strpos($pCoordinateString,':') === FALSE && strpos($pCoordinateString,',') === FALSE) { + // Split out any worksheet name from the coordinate + $worksheet = ''; + $cellAddress = explode('!',$pCoordinateString); + if (count($cellAddress) > 1) { + list($worksheet,$pCoordinateString) = $cellAddress; + } + if ($worksheet > '') $worksheet .= '!'; - // Create absolute coordinate - list($column, $row) = self::coordinateFromString($pCoordinateString); - $column = ltrim($column,'$'); - $row = ltrim($row,'$'); - return $worksheet . '$' . $column . '$' . $row; - } + // Create absolute coordinate + list($column, $row) = self::coordinateFromString($pCoordinateString); + $column = ltrim($column,'$'); + $row = ltrim($row,'$'); + return $worksheet . '$' . $column . '$' . $row; + } - throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells'); - } + throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells'); + } - /** - * Split range into coordinate strings - * - * @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4' - * @return array Array containg one or more arrays containing one or two coordinate strings - * e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11')) - * or array('B4') - */ - public static function splitRange($pRange = 'A1:A1') - { - // Ensure $pRange is a valid range - if(empty($pRange)) { - $pRange = self::DEFAULT_RANGE; - } + /** + * Split range into coordinate strings + * + * @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4' + * @return array Array containg one or more arrays containing one or two coordinate strings + * e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11')) + * or array('B4') + */ + public static function splitRange($pRange = 'A1:A1') + { + // Ensure $pRange is a valid range + if(empty($pRange)) { + $pRange = self::DEFAULT_RANGE; + } - $exploded = explode(',', $pRange); - $counter = count($exploded); - for ($i = 0; $i < $counter; ++$i) { - $exploded[$i] = explode(':', $exploded[$i]); - } - return $exploded; - } + $exploded = explode(',', $pRange); + $counter = count($exploded); + for ($i = 0; $i < $counter; ++$i) { + $exploded[$i] = explode(':', $exploded[$i]); + } + return $exploded; + } - /** - * Build range from coordinate strings - * - * @param array $pRange Array containg one or more arrays containing one or two coordinate strings - * @return string String representation of $pRange - * @throws PHPExcel_Exception - */ - public static function buildRange($pRange) - { - // Verify range - if (!is_array($pRange) || empty($pRange) || !is_array($pRange[0])) { - throw new PHPExcel_Exception('Range does not contain any information'); - } + /** + * Build range from coordinate strings + * + * @param array $pRange Array containg one or more arrays containing one or two coordinate strings + * @return string String representation of $pRange + * @throws PHPExcel_Exception + */ + public static function buildRange($pRange) + { + // Verify range + if (!is_array($pRange) || empty($pRange) || !is_array($pRange[0])) { + throw new PHPExcel_Exception('Range does not contain any information'); + } - // Build range - $imploded = array(); - $counter = count($pRange); - for ($i = 0; $i < $counter; ++$i) { - $pRange[$i] = implode(':', $pRange[$i]); - } - $imploded = implode(',', $pRange); + // Build range + $imploded = array(); + $counter = count($pRange); + for ($i = 0; $i < $counter; ++$i) { + $pRange[$i] = implode(':', $pRange[$i]); + } + $imploded = implode(',', $pRange); - return $imploded; - } + return $imploded; + } - /** - * Calculate range boundaries - * - * @param string $pRange Cell range (e.g. A1:A1) - * @return array Range coordinates array(Start Cell, End Cell) - * where Start Cell and End Cell are arrays (Column Number, Row Number) - */ - public static function rangeBoundaries($pRange = 'A1:A1') - { - // Ensure $pRange is a valid range - if(empty($pRange)) { - $pRange = self::DEFAULT_RANGE; - } + /** + * Calculate range boundaries + * + * @param string $pRange Cell range (e.g. A1:A1) + * @return array Range coordinates array(Start Cell, End Cell) + * where Start Cell and End Cell are arrays (Column Number, Row Number) + */ + public static function rangeBoundaries($pRange = 'A1:A1') + { + // Ensure $pRange is a valid range + if(empty($pRange)) { + $pRange = self::DEFAULT_RANGE; + } - // Uppercase coordinate - $pRange = strtoupper($pRange); + // Uppercase coordinate + $pRange = strtoupper($pRange); - // Extract range - if (strpos($pRange, ':') === FALSE) { - $rangeA = $rangeB = $pRange; - } else { - list($rangeA, $rangeB) = explode(':', $pRange); - } + // Extract range + if (strpos($pRange, ':') === FALSE) { + $rangeA = $rangeB = $pRange; + } else { + list($rangeA, $rangeB) = explode(':', $pRange); + } - // Calculate range outer borders - $rangeStart = self::coordinateFromString($rangeA); - $rangeEnd = self::coordinateFromString($rangeB); + // Calculate range outer borders + $rangeStart = self::coordinateFromString($rangeA); + $rangeEnd = self::coordinateFromString($rangeB); - // Translate column into index - $rangeStart[0] = self::columnIndexFromString($rangeStart[0]); - $rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]); + // Translate column into index + $rangeStart[0] = self::columnIndexFromString($rangeStart[0]); + $rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]); - return array($rangeStart, $rangeEnd); - } + return array($rangeStart, $rangeEnd); + } - /** - * Calculate range dimension - * - * @param string $pRange Cell range (e.g. A1:A1) - * @return array Range dimension (width, height) - */ - public static function rangeDimension($pRange = 'A1:A1') - { - // Calculate range outer borders - list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange); + /** + * Calculate range dimension + * + * @param string $pRange Cell range (e.g. A1:A1) + * @return array Range dimension (width, height) + */ + public static function rangeDimension($pRange = 'A1:A1') + { + // Calculate range outer borders + list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange); - return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) ); - } + return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) ); + } - /** - * Calculate range boundaries - * - * @param string $pRange Cell range (e.g. A1:A1) - * @return array Range coordinates array(Start Cell, End Cell) - * where Start Cell and End Cell are arrays (Column ID, Row Number) - */ - public static function getRangeBoundaries($pRange = 'A1:A1') - { - // Ensure $pRange is a valid range - if(empty($pRange)) { - $pRange = self::DEFAULT_RANGE; - } + /** + * Calculate range boundaries + * + * @param string $pRange Cell range (e.g. A1:A1) + * @return array Range coordinates array(Start Cell, End Cell) + * where Start Cell and End Cell are arrays (Column ID, Row Number) + */ + public static function getRangeBoundaries($pRange = 'A1:A1') + { + // Ensure $pRange is a valid range + if(empty($pRange)) { + $pRange = self::DEFAULT_RANGE; + } - // Uppercase coordinate - $pRange = strtoupper($pRange); + // Uppercase coordinate + $pRange = strtoupper($pRange); - // Extract range - if (strpos($pRange, ':') === FALSE) { - $rangeA = $rangeB = $pRange; - } else { - list($rangeA, $rangeB) = explode(':', $pRange); - } + // Extract range + if (strpos($pRange, ':') === FALSE) { + $rangeA = $rangeB = $pRange; + } else { + list($rangeA, $rangeB) = explode(':', $pRange); + } - return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB)); - } + return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB)); + } - /** - * Column index from string - * - * @param string $pString - * @return int Column index (base 1 !!!) - */ - public static function columnIndexFromString($pString = 'A') - { - // Using a lookup cache adds a slight memory overhead, but boosts speed - // caching using a static within the method is faster than a class static, - // though it's additional memory overhead - static $_indexCache = array(); + /** + * Column index from string + * + * @param string $pString + * @return int Column index (base 1 !!!) + */ + public static function columnIndexFromString($pString = 'A') + { + // Using a lookup cache adds a slight memory overhead, but boosts speed + // caching using a static within the method is faster than a class static, + // though it's additional memory overhead + static $_indexCache = array(); - if (isset($_indexCache[$pString])) - return $_indexCache[$pString]; + if (isset($_indexCache[$pString])) + return $_indexCache[$pString]; - // It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord() - // and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant - // memory overhead either - static $_columnLookup = array( - 'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13, - 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26, - 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13, - 'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26 - ); + // It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord() + // and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant + // memory overhead either + static $_columnLookup = array( + 'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13, + 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26, + 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13, + 'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26 + ); - // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString - // for improved performance - if (isset($pString{0})) { - if (!isset($pString{1})) { - $_indexCache[$pString] = $_columnLookup[$pString]; - return $_indexCache[$pString]; - } elseif(!isset($pString{2})) { - $_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}]; - return $_indexCache[$pString]; - } elseif(!isset($pString{3})) { - $_indexCache[$pString] = $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}]; - return $_indexCache[$pString]; - } - } - throw new PHPExcel_Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty")); - } + // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString + // for improved performance + if (isset($pString{0})) { + if (!isset($pString{1})) { + $_indexCache[$pString] = $_columnLookup[$pString]; + return $_indexCache[$pString]; + } elseif(!isset($pString{2})) { + $_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}]; + return $_indexCache[$pString]; + } elseif(!isset($pString{3})) { + $_indexCache[$pString] = $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}]; + return $_indexCache[$pString]; + } + } + throw new PHPExcel_Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty")); + } - /** - * String from columnindex - * - * @param int $pColumnIndex Column index (base 0 !!!) - * @return string - */ - public static function stringFromColumnIndex($pColumnIndex = 0) - { - // Using a lookup cache adds a slight memory overhead, but boosts speed - // caching using a static within the method is faster than a class static, - // though it's additional memory overhead - static $_indexCache = array(); + /** + * String from columnindex + * + * @param int $pColumnIndex Column index (base 0 !!!) + * @return string + */ + public static function stringFromColumnIndex($pColumnIndex = 0) + { + // Using a lookup cache adds a slight memory overhead, but boosts speed + // caching using a static within the method is faster than a class static, + // though it's additional memory overhead + static $_indexCache = array(); - if (!isset($_indexCache[$pColumnIndex])) { - // Determine column string - if ($pColumnIndex < 26) { - $_indexCache[$pColumnIndex] = chr(65 + $pColumnIndex); - } elseif ($pColumnIndex < 702) { - $_indexCache[$pColumnIndex] = chr(64 + ($pColumnIndex / 26)) . - chr(65 + $pColumnIndex % 26); - } else { - $_indexCache[$pColumnIndex] = chr(64 + (($pColumnIndex - 26) / 676)) . - chr(65 + ((($pColumnIndex - 26) % 676) / 26)) . - chr(65 + $pColumnIndex % 26); - } - } - return $_indexCache[$pColumnIndex]; - } + if (!isset($_indexCache[$pColumnIndex])) { + // Determine column string + if ($pColumnIndex < 26) { + $_indexCache[$pColumnIndex] = chr(65 + $pColumnIndex); + } elseif ($pColumnIndex < 702) { + $_indexCache[$pColumnIndex] = chr(64 + ($pColumnIndex / 26)) . + chr(65 + $pColumnIndex % 26); + } else { + $_indexCache[$pColumnIndex] = chr(64 + (($pColumnIndex - 26) / 676)) . + chr(65 + ((($pColumnIndex - 26) % 676) / 26)) . + chr(65 + $pColumnIndex % 26); + } + } + return $_indexCache[$pColumnIndex]; + } - /** - * Extract all cell references in range - * - * @param string $pRange Range (e.g. A1 or A1:C10 or A1:E10 A20:E25) - * @return array Array containing single cell references - */ - public static function extractAllCellReferencesInRange($pRange = 'A1') { - // Returnvalue - $returnValue = array(); + /** + * Extract all cell references in range + * + * @param string $pRange Range (e.g. A1 or A1:C10 or A1:E10 A20:E25) + * @return array Array containing single cell references + */ + public static function extractAllCellReferencesInRange($pRange = 'A1') { + // Returnvalue + $returnValue = array(); - // Explode spaces - $cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange))); - foreach ($cellBlocks as $cellBlock) { - // Single cell? - if (strpos($cellBlock,':') === FALSE && strpos($cellBlock,',') === FALSE) { - $returnValue[] = $cellBlock; - continue; - } + // Explode spaces + $cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange))); + foreach ($cellBlocks as $cellBlock) { + // Single cell? + if (strpos($cellBlock,':') === FALSE && strpos($cellBlock,',') === FALSE) { + $returnValue[] = $cellBlock; + continue; + } - // Range... - $ranges = self::splitRange($cellBlock); - foreach($ranges as $range) { - // Single cell? - if (!isset($range[1])) { - $returnValue[] = $range[0]; - continue; - } + // Range... + $ranges = self::splitRange($cellBlock); + foreach($ranges as $range) { + // Single cell? + if (!isset($range[1])) { + $returnValue[] = $range[0]; + continue; + } - // Range... - list($rangeStart, $rangeEnd) = $range; - sscanf($rangeStart,'%[A-Z]%d', $startCol, $startRow); - sscanf($rangeEnd,'%[A-Z]%d', $endCol, $endRow); - $endCol++; + // Range... + list($rangeStart, $rangeEnd) = $range; + sscanf($rangeStart,'%[A-Z]%d', $startCol, $startRow); + sscanf($rangeEnd,'%[A-Z]%d', $endCol, $endRow); + $endCol++; - // Current data - $currentCol = $startCol; - $currentRow = $startRow; + // Current data + $currentCol = $startCol; + $currentRow = $startRow; - // Loop cells - while ($currentCol != $endCol) { - while ($currentRow <= $endRow) { - $returnValue[] = $currentCol.$currentRow; - ++$currentRow; - } - ++$currentCol; - $currentRow = $startRow; - } - } - } + // Loop cells + while ($currentCol != $endCol) { + while ($currentRow <= $endRow) { + $returnValue[] = $currentCol.$currentRow; + ++$currentRow; + } + ++$currentCol; + $currentRow = $startRow; + } + } + } - // Sort the result by column and row - $sortKeys = array(); - foreach (array_unique($returnValue) as $coord) { - sscanf($coord,'%[A-Z]%d', $column, $row); - $sortKeys[sprintf('%3s%09d',$column,$row)] = $coord; - } - ksort($sortKeys); + // Sort the result by column and row + $sortKeys = array(); + foreach (array_unique($returnValue) as $coord) { + sscanf($coord,'%[A-Z]%d', $column, $row); + $sortKeys[sprintf('%3s%09d',$column,$row)] = $coord; + } + ksort($sortKeys); - // Return value - return array_values($sortKeys); - } + // Return value + return array_values($sortKeys); + } - /** - * Compare 2 cells - * - * @param PHPExcel_Cell $a Cell a - * @param PHPExcel_Cell $b Cell b - * @return int Result of comparison (always -1 or 1, never zero!) - */ - public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b) - { - if ($a->getRow() < $b->getRow()) { - return -1; - } elseif ($a->getRow() > $b->getRow()) { - return 1; - } elseif (self::columnIndexFromString($a->getColumn()) < self::columnIndexFromString($b->getColumn())) { - return -1; - } else { - return 1; - } - } + /** + * Compare 2 cells + * + * @param PHPExcel_Cell $a Cell a + * @param PHPExcel_Cell $b Cell b + * @return int Result of comparison (always -1 or 1, never zero!) + */ + public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b) + { + if ($a->getRow() < $b->getRow()) { + return -1; + } elseif ($a->getRow() > $b->getRow()) { + return 1; + } elseif (self::columnIndexFromString($a->getColumn()) < self::columnIndexFromString($b->getColumn())) { + return -1; + } else { + return 1; + } + } - /** - * Get value binder to use - * - * @return PHPExcel_Cell_IValueBinder - */ - public static function getValueBinder() { - if (self::$_valueBinder === NULL) { - self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder(); - } + /** + * Get value binder to use + * + * @return PHPExcel_Cell_IValueBinder + */ + public static function getValueBinder() { + if (self::$_valueBinder === NULL) { + self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder(); + } - return self::$_valueBinder; - } + return self::$_valueBinder; + } - /** - * Set value binder to use - * - * @param PHPExcel_Cell_IValueBinder $binder - * @throws PHPExcel_Exception - */ - public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = NULL) { - if ($binder === NULL) { - throw new PHPExcel_Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly."); - } + /** + * Set value binder to use + * + * @param PHPExcel_Cell_IValueBinder $binder + * @throws PHPExcel_Exception + */ + public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = NULL) { + if ($binder === NULL) { + throw new PHPExcel_Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly."); + } - self::$_valueBinder = $binder; - } + self::$_valueBinder = $binder; + } - /** - * Implement PHP __clone to create a deep clone, not just a shallow copy. - */ - public function __clone() { - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { - if ((is_object($value)) && ($key != '_parent')) { - $this->$key = clone $value; - } else { - $this->$key = $value; - } - } - } + /** + * Implement PHP __clone to create a deep clone, not just a shallow copy. + */ + public function __clone() { + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if ((is_object($value)) && ($key != '_parent')) { + $this->$key = clone $value; + } else { + $this->$key = $value; + } + } + } - /** - * Get index to cellXf - * - * @return int - */ - public function getXfIndex() - { - return $this->_xfIndex; - } + /** + * Get index to cellXf + * + * @return int + */ + public function getXfIndex() + { + return $this->_xfIndex; + } - /** - * Set index to cellXf - * - * @param int $pValue - * @return PHPExcel_Cell - */ - public function setXfIndex($pValue = 0) - { - $this->_xfIndex = $pValue; + /** + * Set index to cellXf + * + * @param int $pValue + * @return PHPExcel_Cell + */ + public function setXfIndex($pValue = 0) + { + $this->_xfIndex = $pValue; - return $this->notifyCacheController(); - } + return $this->notifyCacheController(); + } - /** - * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling - */ - public function setFormulaAttributes($pAttributes) - { - $this->_formulaAttributes = $pAttributes; - return $this; - } + /** + * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling + */ + public function setFormulaAttributes($pAttributes) + { + $this->_formulaAttributes = $pAttributes; + return $this; + } - /** - * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling - */ - public function getFormulaAttributes() - { - return $this->_formulaAttributes; - } + /** + * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling + */ + public function getFormulaAttributes() + { + return $this->_formulaAttributes; + } /** * Convert to string * * @return string */ - public function __toString() - { - return (string) $this->getValue(); - } + public function __toString() + { + return (string) $this->getValue(); + } }