diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index ea53919c..b2dd65c4 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -353,9 +353,8 @@ abstract class Coordinate } $cellList = array_merge(...$cells); - $cellList = self::sortCellReferenceArray($cellList); - return $cellList; + return self::sortCellReferenceArray($cellList); } private static function processRangeSetOperators(array $operators, array $cells): array @@ -382,9 +381,10 @@ abstract class Coordinate { // Sort the result by column and row $sortKeys = []; - foreach ($cellList as $coord) { - sscanf($coord, '%[A-Z]%d', $column, $row); - $sortKeys[sprintf('%3s%09d', $column, $row)] = $coord; + foreach ($cellList as $coordinate) { + sscanf($coordinate, '%[A-Z]%d', $column, $row); + $key = (--$row * 16384) + self::columnIndexFromString($column); + $sortKeys[$key] = $coordinate; } ksort($sortKeys); diff --git a/tests/data/CellExtractAllCellReferencesInRange.php b/tests/data/CellExtractAllCellReferencesInRange.php index b005b1fe..a2ecbdd2 100644 --- a/tests/data/CellExtractAllCellReferencesInRange.php +++ b/tests/data/CellExtractAllCellReferencesInRange.php @@ -12,10 +12,10 @@ return [ [ [ 'B4', - 'B5', - 'B6', 'D4', + 'B5', 'D5', + 'B6', 'D6', ], 'B4:B6,D4:D6', @@ -28,13 +28,13 @@ return [ [ [ 'B4', - 'B5', - 'B6', 'C4', - 'C5', - 'C6', 'D4', + 'B5', + 'C5', 'D5', + 'B6', + 'C6', 'D6', ], 'B4:D6', @@ -42,18 +42,18 @@ return [ [ [ 'B4', - 'B5', - 'B6', 'C4', - 'C5', - 'C6', - 'C7', 'D4', + 'B5', + 'C5', 'D5', - 'D6', - 'D7', 'E5', + 'B6', + 'C6', + 'D6', 'E6', + 'C7', + 'D7', 'E7', ], 'B4:D6,C5:E7', @@ -61,8 +61,8 @@ return [ [ [ 'C5', - 'C6', 'D5', + 'C6', 'D6', ], 'B4:D6 C5:E7', @@ -70,23 +70,23 @@ return [ [ [ 'B2', - 'B3', - 'B4', 'C2', - 'C3', - 'C4', - 'C5', 'D2', + 'B3', + 'C3', 'D3', - 'D4', - 'D5', - 'D6', 'E3', + 'B4', + 'C4', + 'D4', 'E4', - 'E5', - 'E6', 'F4', + 'C5', + 'D5', + 'E5', 'F5', + 'D6', + 'E6', 'F6', ], 'B2:D4,C5:D5,E3:E5,D6:E6,F4:F6', @@ -94,23 +94,23 @@ return [ [ [ 'B2', - 'B3', - 'B4', 'C2', - 'C3', - 'C4', - 'C5', 'D2', + 'B3', + 'C3', 'D3', - 'D4', - 'D5', - 'D6', 'E3', + 'B4', + 'C4', + 'D4', 'E4', - 'E5', - 'E6', 'F4', + 'C5', + 'D5', + 'E5', 'F5', + 'D6', + 'E6', 'F6', ], 'B2:D4,C3:E5,D4:F6', @@ -124,8 +124,8 @@ return [ [ [ 'Z2', - 'Z3', 'AA2', + 'Z3', 'AA3', ], 'Z2:AA3',