@@ -72,11 +72,17 @@ public static function INDIRECT($cellAddress, $a1fmt, Cell $cell)
72
72
73
73
[$ cellAddress , $ worksheet , $ sheetName ] = Helpers::extractWorksheet ($ cellAddress , $ cell );
74
74
75
+ if (preg_match ('/^ ' . Calculation::CALCULATION_REGEXP_COLUMNRANGE_RELATIVE . '$/miu ' , $ cellAddress , $ matches )) {
76
+ $ cellAddress = self ::handleRowColumnRanges ($ worksheet , ...explode (': ' , $ cellAddress ));
77
+ } elseif (preg_match ('/^ ' . Calculation::CALCULATION_REGEXP_ROWRANGE_RELATIVE . '$/miu ' , $ cellAddress , $ matches )) {
78
+ $ cellAddress = self ::handleRowColumnRanges ($ worksheet , ...explode (': ' , $ cellAddress ));
79
+ }
80
+
75
81
[$ cellAddress1 , $ cellAddress2 , $ cellAddress ] = Helpers::extractCellAddresses ($ cellAddress , $ a1 , $ cell ->getWorkSheet (), $ sheetName );
76
82
77
83
if (
78
- (!preg_match ('/^ ' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i ' , $ cellAddress1 , $ matches )) ||
79
- (($ cellAddress2 !== null ) && (!preg_match ('/^ ' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i ' , $ cellAddress2 , $ matches )))
84
+ (!preg_match ('/^ ' . Calculation::CALCULATION_REGEXP_CELLREF . '$/miu ' , $ cellAddress1 , $ matches )) ||
85
+ (($ cellAddress2 !== null ) && (!preg_match ('/^ ' . Calculation::CALCULATION_REGEXP_CELLREF . '$/miu ' , $ cellAddress2 , $ matches )))
80
86
) {
81
87
return ExcelError::REF ();
82
88
}
@@ -95,4 +101,22 @@ private static function extractRequiredCells(?Worksheet $worksheet, string $cell
95
101
return Calculation::getInstance ($ worksheet !== null ? $ worksheet ->getParent () : null )
96
102
->extractCellRange ($ cellAddress , $ worksheet , false );
97
103
}
104
+
105
+ private static function handleRowColumnRanges (?Worksheet $ worksheet , string $ start , string $ end ): string
106
+ {
107
+ // Being lazy, we're only checking a single row/column to get the max
108
+ if (ctype_digit ($ start ) && $ start <= 1048576 ) {
109
+ // Max 16,384 columns for Excel2007
110
+ $ endColRef = ($ worksheet !== null ) ? $ worksheet ->getHighestDataColumn ((int ) $ start ) : 'XFD ' ;
111
+
112
+ return "A {$ start }: {$ endColRef }{$ end }" ;
113
+ } elseif (ctype_alpha ($ start ) && strlen ($ start ) <= 3 ) {
114
+ // Max 1,048,576 rows for Excel2007
115
+ $ endRowRef = ($ worksheet !== null ) ? $ worksheet ->getHighestDataRow ($ start ) : 1048576 ;
116
+
117
+ return "{$ start }1: {$ end }{$ endRowRef }" ;
118
+ }
119
+
120
+ return "{$ start }: {$ end }" ;
121
+ }
98
122
}
0 commit comments