@@ -72,11 +72,17 @@ public static function INDIRECT($cellAddress, $a1fmt, Cell $cell)
7272
7373 [$ cellAddress , $ worksheet , $ sheetName ] = Helpers::extractWorksheet ($ cellAddress , $ cell );
7474
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+
7581 [$ cellAddress1 , $ cellAddress2 , $ cellAddress ] = Helpers::extractCellAddresses ($ cellAddress , $ a1 , $ cell ->getWorkSheet (), $ sheetName );
7682
7783 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 )))
8086 ) {
8187 return ExcelError::REF ();
8288 }
@@ -95,4 +101,22 @@ private static function extractRequiredCells(?Worksheet $worksheet, string $cell
95101 return Calculation::getInstance ($ worksheet !== null ? $ worksheet ->getParent () : null )
96102 ->extractCellRange ($ cellAddress , $ worksheet , false );
97103 }
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+ }
98122}
0 commit comments