File tree Expand file tree Collapse file tree 4 files changed +9
-12
lines changed Expand file tree Collapse file tree 4 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -118,17 +118,17 @@ public static function convertToR1C1(
118
118
throw new Exception ('Invalid A1-format Cell Reference ' );
119
119
}
120
120
121
- $ columnId = Coordinate::columnIndexFromString ($ cellReference ['col_ref ' ]);
122
- if ($ cellReference ['absolute_col ' ] === '$ ' ) {
121
+ if ($ cellReference ['col ' ][0 ] === '$ ' ) {
123
122
// Column must be absolute address
124
123
$ currentColumnNumber = null ;
125
124
}
125
+ $ columnId = Coordinate::columnIndexFromString (ltrim ($ cellReference ['col ' ], '$ ' ));
126
126
127
- $ rowId = (int ) $ cellReference ['row_ref ' ];
128
- if ($ cellReference ['absolute_row ' ] === '$ ' ) {
127
+ if ($ cellReference ['row ' ][0 ] === '$ ' ) {
129
128
// Row must be absolute address
130
129
$ currentRowNumber = null ;
131
130
}
131
+ $ rowId = (int ) ltrim ($ cellReference ['row ' ], '$ ' );
132
132
133
133
if ($ currentRowNumber !== null ) {
134
134
if ($ rowId === $ currentRowNumber ) {
Original file line number Diff line number Diff line change @@ -35,9 +35,7 @@ class CellAddress
35
35
public function __construct (string $ cellAddress , ?Worksheet $ worksheet = null )
36
36
{
37
37
$ this ->cellAddress = str_replace ('$ ' , '' , $ cellAddress );
38
- [$ this ->columnName , $ rowId ] = Coordinate::coordinateFromString ($ cellAddress );
39
- $ this ->rowId = (int ) $ rowId ;
40
- $ this ->columnId = Coordinate::columnIndexFromString ($ this ->columnName );
38
+ [$ this ->columnId , $ this ->rowId , $ this ->columnName ] = Coordinate::indexesFromString ($ this ->cellAddress );
41
39
$ this ->worksheet = $ worksheet ;
42
40
}
43
41
Original file line number Diff line number Diff line change 13
13
*/
14
14
abstract class Coordinate
15
15
{
16
- public const A1_COORDINATE_REGEX = '/^(?<absolute_col >\$?)(?<col_ref> [A-Z]{1,3})(?<absolute_row >\$?)(?<row_ref> \d{1,7})$/i ' ;
16
+ public const A1_COORDINATE_REGEX = '/^(?<col >\$?[A-Z]{1,3})(?<row >\$?\d{1,7})$/i ' ;
17
17
18
18
/**
19
19
* Default range variable constant.
@@ -32,7 +32,7 @@ abstract class Coordinate
32
32
public static function coordinateFromString ($ cellAddress )
33
33
{
34
34
if (preg_match (self ::A1_COORDINATE_REGEX , $ cellAddress , $ matches )) {
35
- return [$ matches ['absolute_col ' ] . $ matches [ ' col_ref ' ] , $ matches ['absolute_row ' ] . $ matches [ ' row_ref ' ]];
35
+ return [$ matches ['col ' ] , $ matches ['row ' ]];
36
36
} elseif (self ::coordinateIsRange ($ cellAddress )) {
37
37
throw new Exception ('Cell coordinate string can not be a range of cells ' );
38
38
} elseif ($ cellAddress == '' ) {
Original file line number Diff line number Diff line change @@ -42,9 +42,8 @@ public static function validateCellAddress($cellAddress): string
42
42
public static function validateCellOrCellRange ($ cellRange ): string
43
43
{
44
44
if (is_string ($ cellRange ) || is_numeric ($ cellRange )) {
45
- $ cellRange = (string ) $ cellRange ;
46
45
// Convert a single column reference like 'A' to 'A:A'
47
- $ cellRange = (string ) preg_replace ('/^([A-Z]+)$/ ' , '${1}:${1} ' , $ cellRange );
46
+ $ cellRange = (string ) preg_replace ('/^([A-Z]+)$/ ' , '${1}:${1} ' , ( string ) $ cellRange );
48
47
// Convert a single row reference like '1' to '1:1'
49
48
$ cellRange = (string ) preg_replace ('/^(\d+)$/ ' , '${1}:${1} ' , $ cellRange );
50
49
} elseif (is_object ($ cellRange ) && $ cellRange instanceof CellAddress) {
@@ -85,7 +84,7 @@ public static function validateCellRange($cellRange): string
85
84
public static function definedNameToCoordinate (string $ coordinate , Worksheet $ worksheet ): string
86
85
{
87
86
// Uppercase coordinate
88
- $ testCoordinate = strtoupper ($ coordinate );
87
+ $ coordinate = strtoupper ($ coordinate );
89
88
// Eliminate leading equal sign
90
89
$ testCoordinate = (string ) preg_replace ('/^=/ ' , '' , $ coordinate );
91
90
$ defined = $ worksheet ->getParent ()->getDefinedName ($ testCoordinate , $ worksheet );
You can’t perform that action at this time.
0 commit comments