Unit tests for Cell static methods and creation of PHPExcel_Exception
rather than use of standard Exception
This commit is contained in:
parent
8f3dc270a6
commit
6a14bdce4c
|
@ -40,7 +40,7 @@ class PHPExcel_Cell
|
|||
*
|
||||
* @var PHPExcel_Cell_IValueBinder
|
||||
*/
|
||||
private static $_valueBinder = null;
|
||||
private static $_valueBinder = NULL;
|
||||
|
||||
/**
|
||||
* Column of the cell
|
||||
|
@ -65,10 +65,15 @@ class PHPExcel_Cell
|
|||
|
||||
/**
|
||||
* Calculated value of the cell (used for caching)
|
||||
* 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 reflect 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.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_calculatedValue = null;
|
||||
private $_calculatedValue = NULL;
|
||||
|
||||
/**
|
||||
* Type of the cell data
|
||||
|
@ -94,7 +99,6 @@ class PHPExcel_Cell
|
|||
/**
|
||||
* Attributes of the formula
|
||||
*
|
||||
*
|
||||
*/
|
||||
private $_formulaAttributes;
|
||||
|
||||
|
@ -110,7 +114,7 @@ class PHPExcel_Cell
|
|||
}
|
||||
|
||||
public function detach() {
|
||||
$this->_parent = null;
|
||||
$this->_parent = NULL;
|
||||
}
|
||||
|
||||
public function attach($parent) {
|
||||
|
@ -126,9 +130,9 @@ class PHPExcel_Cell
|
|||
* @param mixed $pValue
|
||||
* @param string $pDataType
|
||||
* @param PHPExcel_Worksheet $pSheet
|
||||
* @throws Exception
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function __construct($pColumn = 'A', $pRow = 1, $pValue = null, $pDataType = null, PHPExcel_Worksheet $pSheet = null)
|
||||
public function __construct($pColumn = 'A', $pRow = 1, $pValue = NULL, $pDataType = NULL, PHPExcel_Worksheet $pSheet = NULL)
|
||||
{
|
||||
// Initialise cell coordinate
|
||||
$this->_column = strtoupper($pColumn);
|
||||
|
@ -141,13 +145,13 @@ class PHPExcel_Cell
|
|||
$this->_parent = $pSheet;
|
||||
|
||||
// Set datatype?
|
||||
if ($pDataType !== null) {
|
||||
if ($pDataType !== NULL) {
|
||||
if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2)
|
||||
$pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
|
||||
$this->_dataType = $pDataType;
|
||||
} else {
|
||||
if (!self::getValueBinder()->bindValue($this, $pValue)) {
|
||||
throw new Exception("Value could not be bound to cell.");
|
||||
throw new PHPExcel_Exception("Value could not be bound to cell.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,8 +206,10 @@ class PHPExcel_Cell
|
|||
*/
|
||||
public function getFormattedValue()
|
||||
{
|
||||
return (string) PHPExcel_Style_NumberFormat::toFormattedString( $this->getCalculatedValue(),
|
||||
$this->_parent->getParent()->getCellXfByIndex($this->getXfIndex())->getNumberFormat()->getFormatCode()
|
||||
return (string) PHPExcel_Style_NumberFormat::toFormattedString(
|
||||
$this->getCalculatedValue(),
|
||||
$this->_parent->getParent()->getCellXfByIndex($this->getXfIndex())
|
||||
->getNumberFormat()->getFormatCode()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -214,11 +220,12 @@ class PHPExcel_Cell
|
|||
*
|
||||
* @param mixed $pValue Value
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function setValue($pValue = null)
|
||||
public function setValue($pValue = NULL)
|
||||
{
|
||||
if (!self::getValueBinder()->bindValue($this, $pValue)) {
|
||||
throw new Exception("Value could not be bound to cell.");
|
||||
throw new PHPExcel_Exception("Value could not be bound to cell.");
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
@ -229,9 +236,9 @@ class PHPExcel_Cell
|
|||
* @param mixed $pValue Value
|
||||
* @param string $pDataType Explicit data type
|
||||
* @return PHPExcel_Cell
|
||||
* @throws Exception
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
|
||||
public function setValueExplicit($pValue = NULL, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
|
||||
{
|
||||
// set the value according to data type
|
||||
switch ($pDataType) {
|
||||
|
@ -242,25 +249,20 @@ class PHPExcel_Cell
|
|||
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 Exception('Invalid datatype: ' . $pDataType);
|
||||
throw new PHPExcel_Exception('Invalid datatype: ' . $pDataType);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -276,8 +278,9 @@ class PHPExcel_Cell
|
|||
* @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
|
||||
*
|
||||
* @return mixed
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function getCalculatedValue($resetLog=true)
|
||||
public function getCalculatedValue($resetLog = TRUE)
|
||||
{
|
||||
// echo 'Cell '.$this->getCoordinate().' value is a '.$this->_dataType.' with a value of '.$this->getValue().'<br />';
|
||||
if ($this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) {
|
||||
|
@ -292,7 +295,11 @@ class PHPExcel_Cell
|
|||
}
|
||||
// echo 'Calculation Exception: '.$ex->getMessage().'<br />';
|
||||
$result = '#N/A';
|
||||
throw(new Exception($this->getParent()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage()));
|
||||
throw(
|
||||
new PHPExcel_Exception(
|
||||
$this->getParent()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($result === '#Not Yet Implemented') {
|
||||
|
@ -305,21 +312,19 @@ class PHPExcel_Cell
|
|||
|
||||
// if ($this->_value === NULL) {
|
||||
// echo 'Cell '.$this->getCoordinate().' has no value, formula or otherwise<br />';
|
||||
// return null;
|
||||
// return NULL;
|
||||
// }
|
||||
// echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'<br />';
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set calculated value (used for caching)
|
||||
*
|
||||
* @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
|
||||
* Set old calculated value (cached)
|
||||
*
|
||||
* @param mixed $pValue Value
|
||||
* @return PHPExcel_Cell
|
||||
*/
|
||||
public function setCalculatedValue($pValue = null)
|
||||
public function setCalculatedValue($pValue = NULL)
|
||||
{
|
||||
if ($pValue !== NULL) {
|
||||
$this->_calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue;
|
||||
|
@ -330,6 +335,11 @@ class PHPExcel_Cell
|
|||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -365,44 +375,46 @@ class PHPExcel_Cell
|
|||
}
|
||||
|
||||
/**
|
||||
* Has Data validation?
|
||||
* Does this cell contain Data validation rules?
|
||||
*
|
||||
* @return boolean
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function hasDataValidation()
|
||||
{
|
||||
if (!isset($this->_parent)) {
|
||||
throw new Exception('Cannot check for data validation when cell is not bound to a worksheet');
|
||||
throw new PHPExcel_Exception('Cannot check for data validation when cell is not bound to a worksheet');
|
||||
}
|
||||
|
||||
return $this->_parent->dataValidationExists($this->getCoordinate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Data validation
|
||||
* Get Data validation rules
|
||||
*
|
||||
* @return PHPExcel_Cell_DataValidation
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function getDataValidation()
|
||||
{
|
||||
if (!isset($this->_parent)) {
|
||||
throw new Exception('Cannot get data validation for cell that is not bound to a worksheet');
|
||||
throw new PHPExcel_Exception('Cannot get data validation for cell that is not bound to a worksheet');
|
||||
}
|
||||
|
||||
return $this->_parent->getDataValidation($this->getCoordinate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Data validation
|
||||
* Set Data validation rules
|
||||
*
|
||||
* @param PHPExcel_Cell_DataValidation $pDataValidation
|
||||
* @throws Exception
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = null)
|
||||
public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = NULL)
|
||||
{
|
||||
if (!isset($this->_parent)) {
|
||||
throw new Exception('Cannot set data validation for cell that is not bound to a worksheet');
|
||||
throw new PHPExcel_Exception('Cannot set data validation for cell that is not bound to a worksheet');
|
||||
}
|
||||
|
||||
$this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation);
|
||||
|
@ -411,14 +423,15 @@ class PHPExcel_Cell
|
|||
}
|
||||
|
||||
/**
|
||||
* Has Hyperlink
|
||||
* Does this cell contain a Hyperlink?
|
||||
*
|
||||
* @return boolean
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function hasHyperlink()
|
||||
{
|
||||
if (!isset($this->_parent)) {
|
||||
throw new Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
|
||||
throw new PHPExcel_Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
|
||||
}
|
||||
|
||||
return $this->_parent->hyperlinkExists($this->getCoordinate());
|
||||
|
@ -427,13 +440,13 @@ class PHPExcel_Cell
|
|||
/**
|
||||
* Get Hyperlink
|
||||
*
|
||||
* @throws Exception
|
||||
* @return PHPExcel_Cell_Hyperlink
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function getHyperlink()
|
||||
{
|
||||
if (!isset($this->_parent)) {
|
||||
throw new Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
|
||||
throw new PHPExcel_Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
|
||||
}
|
||||
|
||||
return $this->_parent->getHyperlink($this->getCoordinate());
|
||||
|
@ -443,13 +456,13 @@ class PHPExcel_Cell
|
|||
* Set Hyperlink
|
||||
*
|
||||
* @param PHPExcel_Cell_Hyperlink $pHyperlink
|
||||
* @throws Exception
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = null)
|
||||
public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = NULL)
|
||||
{
|
||||
if (!isset($this->_parent)) {
|
||||
throw new Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
|
||||
throw new PHPExcel_Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
|
||||
}
|
||||
|
||||
$this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink);
|
||||
|
@ -458,7 +471,7 @@ class PHPExcel_Cell
|
|||
}
|
||||
|
||||
/**
|
||||
* Get parent
|
||||
* Get parent worksheet
|
||||
*
|
||||
* @return PHPExcel_Worksheet
|
||||
*/
|
||||
|
@ -486,10 +499,10 @@ class PHPExcel_Cell
|
|||
*/
|
||||
public function isInRange($pRange = 'A1:A1')
|
||||
{
|
||||
list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
|
||||
list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange);
|
||||
|
||||
// Translate properties
|
||||
$myColumn = PHPExcel_Cell::columnIndexFromString($this->getColumn());
|
||||
$myColumn = self::columnIndexFromString($this->getColumn());
|
||||
$myRow = $this->getRow();
|
||||
|
||||
// Verify if cell is in range
|
||||
|
@ -503,41 +516,50 @@ class PHPExcel_Cell
|
|||
*
|
||||
* @param string $pCoordinateString
|
||||
* @return array Array containing column and row (indexes 0 and 1)
|
||||
* @throws Exception
|
||||
* @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 Exception('Cell coordinate string can not be a range of cells.');
|
||||
} 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 Exception('Cell coordinate can not be zero-length string.');
|
||||
} else {
|
||||
throw new Exception('Invalid cell coordinate '.$pCoordinateString);
|
||||
throw new PHPExcel_Exception('Cell coordinate can not be zero-length string');
|
||||
}
|
||||
|
||||
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 Exception
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public static function absoluteReference($pCoordinateString = 'A1')
|
||||
{
|
||||
if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) {
|
||||
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 '$'.$pCoordinateString;
|
||||
return $worksheet . '$' . $pCoordinateString;
|
||||
} elseif (ctype_alpha($pCoordinateString)) {
|
||||
return '$'.strtoupper($pCoordinateString);
|
||||
return $worksheet . '$' . strtoupper($pCoordinateString);
|
||||
}
|
||||
return self::absoluteCoordinate($pCoordinateString);
|
||||
} else {
|
||||
throw new Exception("Coordinate string should not be a cell range.");
|
||||
return $worksheet . self::absoluteCoordinate($pCoordinateString);
|
||||
}
|
||||
|
||||
throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -545,34 +567,35 @@ class PHPExcel_Cell
|
|||
*
|
||||
* @param string $pCoordinateString e.g. 'A1'
|
||||
* @return string Absolute coordinate e.g. '$A$1'
|
||||
* @throws Exception
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public static function absoluteCoordinate($pCoordinateString = 'A1')
|
||||
{
|
||||
if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) {
|
||||
// Create absolute coordinate
|
||||
if (strpos($pCoordinateString,':') === FALSE && strpos($pCoordinateString,',') === FALSE) {
|
||||
// Split out any worksheet name from the coordinate
|
||||
$worksheet = '';
|
||||
$cellAddress = explode('!',$pCoordinateString);
|
||||
if (count($cellAddress) == 2) {
|
||||
if (count($cellAddress) > 1) {
|
||||
list($worksheet,$pCoordinateString) = $cellAddress;
|
||||
}
|
||||
if ($worksheet > '') $worksheet .= '!';
|
||||
|
||||
list($column, $row) = PHPExcel_Cell::coordinateFromString($pCoordinateString);
|
||||
if ($column[0] == '$') $column = substr($column,1);
|
||||
if ($row[0] == '$') $row = substr($row,1);
|
||||
if ($worksheet > '')
|
||||
$worksheet .= '!';
|
||||
// Create absolute coordinate
|
||||
list($column, $row) = self::coordinateFromString($pCoordinateString);
|
||||
$column = ltrim($column,'$');
|
||||
$row = ltrim($row,'$');
|
||||
return $worksheet . '$' . $column . '$' . $row;
|
||||
} else {
|
||||
throw new Exception("Coordinate string should not be a cell range.");
|
||||
}
|
||||
|
||||
throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
|
||||
}
|
||||
|
||||
/**
|
||||
* Split range into coordinate strings
|
||||
*
|
||||
* @param string $pRange
|
||||
* @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11'
|
||||
* @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'))
|
||||
*/
|
||||
public static function splitRange($pRange = 'A1:A1')
|
||||
{
|
||||
|
@ -589,13 +612,13 @@ class PHPExcel_Cell
|
|||
*
|
||||
* @param array $pRange Array containg one or more arrays containing one or two coordinate strings
|
||||
* @return string String representation of $pRange
|
||||
* @throws Exception
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public static function buildRange($pRange)
|
||||
{
|
||||
// Verify range
|
||||
if (!is_array($pRange) || empty($pRange) || !is_array($pRange[0])) {
|
||||
throw new Exception('Range does not contain any information.');
|
||||
throw new PHPExcel_Exception('Range does not contain any information');
|
||||
}
|
||||
|
||||
// Build range
|
||||
|
@ -621,19 +644,19 @@ class PHPExcel_Cell
|
|||
$pRange = strtoupper($pRange);
|
||||
|
||||
// Extract range
|
||||
if (strpos($pRange, ':') === false) {
|
||||
if (strpos($pRange, ':') === FALSE) {
|
||||
$rangeA = $rangeB = $pRange;
|
||||
} else {
|
||||
list($rangeA, $rangeB) = explode(':', $pRange);
|
||||
}
|
||||
|
||||
// Calculate range outer borders
|
||||
$rangeStart = PHPExcel_Cell::coordinateFromString($rangeA);
|
||||
$rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB);
|
||||
$rangeStart = self::coordinateFromString($rangeA);
|
||||
$rangeEnd = self::coordinateFromString($rangeB);
|
||||
|
||||
// Translate column into index
|
||||
$rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]);
|
||||
$rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]);
|
||||
$rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
|
||||
$rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
|
||||
|
||||
return array($rangeStart, $rangeEnd);
|
||||
}
|
||||
|
@ -647,7 +670,7 @@ class PHPExcel_Cell
|
|||
public static function rangeDimension($pRange = 'A1:A1')
|
||||
{
|
||||
// Calculate range outer borders
|
||||
list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
|
||||
list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange);
|
||||
|
||||
return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
|
||||
}
|
||||
|
@ -664,7 +687,7 @@ class PHPExcel_Cell
|
|||
$pRange = strtoupper($pRange);
|
||||
|
||||
// Extract range
|
||||
if (strpos($pRange, ':') === false) {
|
||||
if (strpos($pRange, ':') === FALSE) {
|
||||
$rangeA = $rangeB = $pRange;
|
||||
} else {
|
||||
list($rangeA, $rangeB) = explode(':', $pRange);
|
||||
|
@ -714,7 +737,7 @@ class PHPExcel_Cell
|
|||
return $_indexCache[$pString];
|
||||
}
|
||||
}
|
||||
throw new Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty") . ".");
|
||||
throw new PHPExcel_Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -760,13 +783,13 @@ class PHPExcel_Cell
|
|||
$cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange)));
|
||||
foreach ($cellBlocks as $cellBlock) {
|
||||
// Single cell?
|
||||
if (strpos($cellBlock,':') === false && strpos($cellBlock,',') === false) {
|
||||
if (strpos($cellBlock,':') === FALSE && strpos($cellBlock,',') === FALSE) {
|
||||
$returnValue[] = $cellBlock;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Range...
|
||||
$ranges = PHPExcel_Cell::splitRange($cellBlock);
|
||||
$ranges = self::splitRange($cellBlock);
|
||||
foreach($ranges as $range) {
|
||||
// Single cell?
|
||||
if (!isset($range[1])) {
|
||||
|
@ -813,7 +836,7 @@ class PHPExcel_Cell
|
|||
return -1;
|
||||
} elseif ($a->_row > $b->_row) {
|
||||
return 1;
|
||||
} elseif (PHPExcel_Cell::columnIndexFromString($a->_column) < PHPExcel_Cell::columnIndexFromString($b->_column)) {
|
||||
} elseif (self::columnIndexFromString($a->_column) < self::columnIndexFromString($b->_column)) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
|
@ -839,7 +862,7 @@ class PHPExcel_Cell
|
|||
* @param PHPExcel_Cell_IValueBinder $binder
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = null) {
|
||||
public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = NULL) {
|
||||
if ($binder === NULL) {
|
||||
throw new Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2012 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel
|
||||
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Exception
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel
|
||||
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Exception extends Exception {
|
||||
/**
|
||||
* Error handler callback
|
||||
*
|
||||
* @param mixed $code
|
||||
* @param mixed $string
|
||||
* @param mixed $file
|
||||
* @param mixed $line
|
||||
* @param mixed $context
|
||||
*/
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context) {
|
||||
$e = new self($string, $code);
|
||||
$e->line = $line;
|
||||
$e->file = $file;
|
||||
throw $e;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
|
||||
|
||||
require_once 'testDataFileIterator.php';
|
||||
|
||||
class CellTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
|
||||
}
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerColumnString
|
||||
*/
|
||||
public function testColumnIndexFromString()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','columnIndexFromString'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerColumnString()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/ColumnString.data');
|
||||
}
|
||||
|
||||
public function testColumnIndexFromStringTooLong()
|
||||
{
|
||||
$cellAddress = 'ABCD';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'),$cellAddress);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
public function testColumnIndexFromStringTooShort()
|
||||
{
|
||||
$cellAddress = '';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'),$cellAddress);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Column string index can not be empty');
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerColumnIndex
|
||||
*/
|
||||
public function testStringFromColumnIndex()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','stringFromColumnIndex'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerColumnIndex()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/ColumnIndex.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCoordinates
|
||||
*/
|
||||
public function testCoordinateFromString()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','coordinateFromString'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerCoordinates()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellCoordinates.data');
|
||||
}
|
||||
|
||||
public function testCoordinateFromStringWithRangeAddress()
|
||||
{
|
||||
$cellAddress = 'A1:AI2012';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
public function testCoordinateFromStringWithEmptyAddress()
|
||||
{
|
||||
$cellAddress = '';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
public function testCoordinateFromStringWithInvalidAddress()
|
||||
{
|
||||
$cellAddress = 'AI';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Invalid cell coordinate '.$cellAddress);
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAbsoluteCoordinates
|
||||
*/
|
||||
public function testAbsoluteCoordinateFromString()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','absoluteCoordinate'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerAbsoluteCoordinates()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellAbsoluteCoordinate.data');
|
||||
}
|
||||
|
||||
public function testAbsoluteCoordinateFromStringWithRangeAddress()
|
||||
{
|
||||
$cellAddress = 'A1:AI2012';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','absoluteCoordinate'),$cellAddress);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAbsoluteReferences
|
||||
*/
|
||||
public function testAbsoluteReferenceFromString()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','absoluteReference'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerAbsoluteReferences()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellAbsoluteReference.data');
|
||||
}
|
||||
|
||||
public function testAbsoluteReferenceFromStringWithRangeAddress()
|
||||
{
|
||||
$cellAddress = 'A1:AI2012';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','absoluteReference'),$cellAddress);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSplitRange
|
||||
*/
|
||||
public function testSplitRange()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','splitRange'),$args);
|
||||
foreach($result as $key => $split) {
|
||||
$this->assertEquals($expectedResult[$key], $split);
|
||||
}
|
||||
}
|
||||
|
||||
public function providerSplitRange()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellSplitRange.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerBuildRange
|
||||
*/
|
||||
public function testBuildRange()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','buildRange'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerBuildRange()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellBuildRange.data');
|
||||
}
|
||||
|
||||
public function testBuildRangeInvalid()
|
||||
{
|
||||
$cellRange = '';
|
||||
try {
|
||||
$result = call_user_func(array('PHPExcel_Cell','buildRange'),$cellRange);
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
$this->assertEquals($e->getMessage(), 'Range does not contain any information');
|
||||
return;
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerRangeBoundaries
|
||||
*/
|
||||
public function testRangeBoundaries()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','rangeBoundaries'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerRangeBoundaries()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellRangeBoundaries.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerRangeDimension
|
||||
*/
|
||||
public function testRangeDimension()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','rangeDimension'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerRangeDimension()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellRangeDimension.data');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
"A1", "$A$1"
|
||||
"A12", "$A$12"
|
||||
"J1", "$J$1"
|
||||
"J20", "$J$20"
|
||||
"AI1", "$AI$1"
|
||||
"AI2012", "$AI$2012"
|
||||
"'Worksheet1'!AI256", "'Worksheet1'!$AI$256"
|
||||
"Worksheet1!AI256", "Worksheet1!$AI$256"
|
||||
"'Data Worksheet'!AI256", "'Data Worksheet'!$AI$256"
|
||||
"'Worksheet1'!$AI256", "'Worksheet1'!$AI$256"
|
||||
"'Worksheet1'!AI$256", "'Worksheet1'!$AI$256"
|
||||
"'Worksheet1'!$AI$256", "'Worksheet1'!$AI$256"
|
|
@ -0,0 +1,16 @@
|
|||
"A1", "$A$1"
|
||||
"A12", "$A$12"
|
||||
"J1", "$J$1"
|
||||
"J20", "$J$20"
|
||||
"AI1", "$AI$1"
|
||||
"AI2012", "$AI$2012"
|
||||
"'Worksheet1'!AI256", "'Worksheet1'!$AI$256"
|
||||
"Worksheet1!AI256", "Worksheet1!$AI$256"
|
||||
"'Data Worksheet'!AI256", "'Data Worksheet'!$AI$256"
|
||||
"AI", "$AI"
|
||||
2012, "$2012"
|
||||
"Worksheet1!AI", "Worksheet1!$AI"
|
||||
"Worksheet1!256", "Worksheet1!$256"
|
||||
"'Worksheet1'!$AI256", "'Worksheet1'!$AI$256"
|
||||
"'Worksheet1'!AI$256", "'Worksheet1'!$AI$256"
|
||||
"'Worksheet1'!$AI$256", "'Worksheet1'!$AI$256"
|
|
@ -0,0 +1,2 @@
|
|||
{"B4"|"E9"}, "B4:E9"
|
||||
{"B4"|"E9";"H2"|"O11"}, "B4:E9,H2:O11"
|
|
@ -0,0 +1,6 @@
|
|||
"A1", {"A";1}
|
||||
"A12", {"A";12}
|
||||
"J1", {"J";1}
|
||||
"J20", {"J";20}
|
||||
"AI1", {"AI";1}
|
||||
"AI2012", {"AI";2012}
|
|
@ -0,0 +1,2 @@
|
|||
"B4:E9", {2|4;5|9}
|
||||
"B4", {2|4;2|4}
|
|
@ -0,0 +1,2 @@
|
|||
"B4:E9", {4;6}
|
||||
"B4", {1;1}
|
|
@ -0,0 +1,3 @@
|
|||
"B4:E9", {"B4"|"E9"}
|
||||
"B4", {"B4"}
|
||||
"B4:E9,H2:O11", {"B4"|"E9";"H2"|"O11"}
|
|
@ -0,0 +1,9 @@
|
|||
0, "A"
|
||||
25, "Z"
|
||||
26, "AA"
|
||||
27, "AB"
|
||||
51, "AZ"
|
||||
52, "BA"
|
||||
701, "ZZ"
|
||||
702, "AAA"
|
||||
1378, "BAA"
|
|
@ -0,0 +1,9 @@
|
|||
"A", 1
|
||||
"Z", 26
|
||||
"AA", 27
|
||||
"AB", 28
|
||||
"AZ", 52
|
||||
"BA", 53
|
||||
"ZZ", 702
|
||||
"AAA", 703
|
||||
"BAA", 1379
|
Loading…
Reference in New Issue