GH18 - Modify extractAllCellReferencesInRange() behaviour for , and space
range separators
This commit is contained in:
parent
5c32ecee0a
commit
83c083392a
|
@ -593,9 +593,10 @@ class PHPExcel_Cell
|
|||
/**
|
||||
* Split range into coordinate strings
|
||||
*
|
||||
* @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11'
|
||||
* @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')
|
||||
{
|
||||
|
@ -636,7 +637,8 @@ class PHPExcel_Cell
|
|||
* Calculate range boundaries
|
||||
*
|
||||
* @param string $pRange Cell range (e.g. A1:A1)
|
||||
* @return array Range coordinates (Start Cell, End Cell) where Start Cell and End Cell are arrays (Column Number, Row Number)
|
||||
* @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')
|
||||
{
|
||||
|
@ -679,7 +681,8 @@ class PHPExcel_Cell
|
|||
* Calculate range boundaries
|
||||
*
|
||||
* @param string $pRange Cell range (e.g. A1:A1)
|
||||
* @return array Range boundaries (staring Column, starting Row, Final Column, Final Row)
|
||||
* @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')
|
||||
{
|
||||
|
@ -772,7 +775,7 @@ class PHPExcel_Cell
|
|||
/**
|
||||
* Extract all cell references in range
|
||||
*
|
||||
* @param string $pRange Range (e.g. A1 or A1:A10 or A1:A10 A100:A1000)
|
||||
* @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') {
|
||||
|
@ -819,8 +822,16 @@ class PHPExcel_Cell
|
|||
}
|
||||
}
|
||||
|
||||
// Sort the result by column and row
|
||||
$sortKeys = array();
|
||||
foreach (array_unique($returnValue) as $coord) {
|
||||
list($column,$row) = sscanf($coord,'%[A-Z]%d');
|
||||
$sortKeys[sprintf('%3s%09d',$column,$row)] = $coord;
|
||||
}
|
||||
ksort($sortKeys);
|
||||
|
||||
// Return value
|
||||
return $returnValue;
|
||||
return array_values($sortKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -187,9 +187,13 @@ class CellTest extends PHPUnit_Framework_TestCase
|
|||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','splitRange'),$args);
|
||||
foreach($result as $key => $split) {
|
||||
if (!is_array($expectedResult[$key])) {
|
||||
$this->assertEquals($expectedResult[$key], $split[0]);
|
||||
} else {
|
||||
$this->assertEquals($expectedResult[$key], $split);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function providerSplitRange()
|
||||
{
|
||||
|
@ -256,4 +260,36 @@ class CellTest extends PHPUnit_Framework_TestCase
|
|||
return new testDataFileIterator('rawTestData/CellRangeDimension.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerGetRangeBoundaries
|
||||
*/
|
||||
public function testGetRangeBoundaries()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','getRangeBoundaries'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerGetRangeBoundaries()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellGetRangeBoundaries.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerExtractAllCellReferencesInRange
|
||||
*/
|
||||
public function testExtractAllCellReferencesInRange()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Cell','extractAllCellReferencesInRange'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerExtractAllCellReferencesInRange()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/CellExtractAllCellReferencesInRange.data');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
"B4:B6", {"B4";"B5";"B6"}
|
||||
'"B4:B6,D4:D6"', {"B4";"B5";"B6";"D4";"D5";"D6"}
|
||||
'"B4:B6 D4:D6"', {"B4";"B5";"B6";"D4";"D5";"D6"}
|
||||
"B4:D6", {"B4";"B5";"B6";"C4";"C5";"C6";"D4";"D5";"D6"}
|
||||
'"B4:D6,C5:E7"', {"B4";"B5";"B6";"C4";"C5";"C6";"C7";"D4";"D5";"D6";"D7";"E5";"E6";"E7"}
|
||||
'"B4:D6 C5:E7"', {"B4";"B5";"B6";"C4";"C5";"C6";"C7";"D4";"D5";"D6";"D7";"E5";"E6";"E7"}
|
||||
"B2:D4 C5:D5 E3:E5 D6:E6 F4:F6", {"B2";"B3";"B4";"C2";"C3";"C4";"C5";"D2";"D3";"D4";"D5";"D6";"E3";"E4";"E5";"E6";"F4";"F5";"F6"}
|
||||
"B2:D4 C3:E5 D4:F6", {"B2";"B3";"B4";"C2";"C3";"C4";"C5";"D2";"D3";"D4";"D5";"D6";"E3";"E4";"E5";"E6";"F4";"F5";"F6"}
|
||||
"B4:B6 B8", {"B4";"B5";"B6";"B8"}
|
|
@ -0,0 +1,2 @@
|
|||
"B4:E9", {"B"|4;"E"|9}
|
||||
"B4", {"B"|4;"B"|4}
|
Loading…
Reference in New Issue