@@ -4408,7 +4408,9 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
44084408 if ($ rangeWS1 !== '' ) {
44094409 $ rangeWS1 .= '! ' ;
44104410 }
4411- $ rangeSheetRef = trim ($ rangeSheetRef , "' " );
4411+ if (str_starts_with ($ rangeSheetRef , "' " )) {
4412+ $ rangeSheetRef = Worksheet::unApostrophizeTitle ($ rangeSheetRef );
4413+ }
44124414 [$ rangeWS2 , $ val ] = Worksheet::extractSheetTitle ($ val , true );
44134415 if ($ rangeWS2 !== '' ) {
44144416 $ rangeWS2 .= '! ' ;
@@ -4424,11 +4426,10 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
44244426 if (ctype_digit ($ val ) && $ val <= 1048576 ) {
44254427 // Row range
44264428 $ stackItemType = 'Row Reference ' ;
4427- /** @var int $valx */
44284429 $ valx = $ val ;
44294430 $ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataColumn ($ valx ) : AddressRange::MAX_COLUMN ; // Max 16,384 columns for Excel2007
44304431 $ val = "{$ rangeWS2 }{$ endRowColRef }{$ val }" ;
4431- } elseif (ctype_alpha ($ val ) && is_string ( $ val ) && strlen ($ val ) <= 3 ) {
4432+ } elseif (ctype_alpha ($ val ) && strlen ($ val ) <= 3 ) {
44324433 // Column range
44334434 $ stackItemType = 'Column Reference ' ;
44344435 $ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataRow ($ val ) : AddressRange::MAX_ROW ; // Max 1,048,576 rows for Excel2007
@@ -4562,7 +4563,7 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
45624563
45634564 while (($ op = $ stack ->pop ()) !== null ) {
45644565 // pop everything off the stack and push onto output
4565- if (( is_array ( $ op) && $ op ['value ' ] == '( ' ) ) {
4566+ if ($ op ['value ' ] == '( ' ) {
45664567 return $ this ->raiseFormulaError ("Formula Error: Expecting ')' " ); // if there are any opening braces on the stack, then braces were unbalanced
45674568 }
45684569 $ output [] = $ op ;
@@ -4766,18 +4767,18 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
47664767 }
47674768 }
47684769 if (str_contains ($ operand1Data ['reference ' ] ?? '' , '! ' )) {
4769- [$ sheet1 , $ operand1Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand1Data ['reference ' ], true );
4770+ [$ sheet1 , $ operand1Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand1Data ['reference ' ], true , true );
47704771 } else {
47714772 $ sheet1 = ($ pCellWorksheet !== null ) ? $ pCellWorksheet ->getTitle () : '' ;
47724773 }
47734774 $ sheet1 ??= '' ;
47744775
4775- [$ sheet2 , $ operand2Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand2Data ['reference ' ], true );
4776+ [$ sheet2 , $ operand2Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand2Data ['reference ' ], true , true );
47764777 if (empty ($ sheet2 )) {
47774778 $ sheet2 = $ sheet1 ;
47784779 }
47794780
4780- if (trim ( $ sheet1, " ' " ) === trim ( $ sheet2, " ' " ) ) {
4781+ if ($ sheet1 === $ sheet2 ) {
47814782 if ($ operand1Data ['reference ' ] === null && $ cell !== null ) {
47824783 if (is_array ($ operand1Data ['value ' ])) {
47834784 $ operand1Data ['reference ' ] = $ cell ->getCoordinate ();
@@ -4819,7 +4820,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
48194820 if ($ breakNeeded ) {
48204821 break ;
48214822 }
4822- $ cellRef = Coordinate::stringFromColumnIndex (min ($ oCol ) + 1 ) . min ($ oRow ) . ': ' . Coordinate::stringFromColumnIndex (max ($ oCol ) + 1 ) . max ($ oRow );
4823+ $ cellRef = Coordinate::stringFromColumnIndex (min ($ oCol ) + 1 ) . min ($ oRow ) . ': ' . Coordinate::stringFromColumnIndex (max ($ oCol ) + 1 ) . max ($ oRow ); // @phpstan-ignore-line
48234824 if ($ pCellParent !== null && $ this ->spreadsheet !== null ) {
48244825 $ cellValue = $ this ->extractCellRange ($ cellRef , $ this ->spreadsheet ->getSheetByName ($ sheet1 ), false );
48254826 } else {
@@ -4917,8 +4918,8 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
49174918 $ this ->debugLog ->writeDebugLog ('Evaluation Result is %s ' , $ this ->showTypeDetails ($ cellIntersect ));
49184919 $ stack ->push ('Error ' , ExcelError::null (), null );
49194920 } else {
4920- $ cellRef = Coordinate::stringFromColumnIndex (min ($ oCol ) + 1 ) . min ($ oRow ) . ': '
4921- . Coordinate::stringFromColumnIndex (max ($ oCol ) + 1 ) . max ($ oRow );
4921+ $ cellRef = Coordinate::stringFromColumnIndex (min ($ oCol ) + 1 ) . min ($ oRow ) . ': ' // @phpstan-ignore-line
4922+ . Coordinate::stringFromColumnIndex (max ($ oCol ) + 1 ) . max ($ oRow ); // @phpstan-ignore-line
49224923 $ this ->debugLog ->writeDebugLog ('Evaluation Result is %s ' , $ this ->showTypeDetails ($ cellIntersect ));
49234924 $ stack ->push ('Value ' , $ cellIntersect , $ cellRef );
49244925 }
@@ -5058,6 +5059,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
50585059 }
50595060
50605061 $ functionName = $ matches [1 ];
5062+ /** @var array $argCount */
50615063 $ argCount = $ stack ->pop ();
50625064 $ argCount = $ argCount ['value ' ];
50635065 if ($ functionName !== 'MKMATRIX ' ) {
@@ -5088,9 +5090,10 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
50885090 && (isset (self ::$ phpSpreadsheetFunctions [$ functionName ]['passByReference ' ][$ a ]))
50895091 && (self ::$ phpSpreadsheetFunctions [$ functionName ]['passByReference ' ][$ a ])
50905092 ) {
5093+ /** @var array $arg */
50915094 if ($ arg ['reference ' ] === null ) {
50925095 $ nextArg = $ cellID ;
5093- if ($ functionName === 'ISREF ' && is_array ( $ arg ) && ($ arg ['type ' ] ?? '' ) === 'Value ' ) {
5096+ if ($ functionName === 'ISREF ' && ($ arg ['type ' ] ?? '' ) === 'Value ' ) {
50945097 if (array_key_exists ('value ' , $ arg )) {
50955098 $ argValue = $ arg ['value ' ];
50965099 if (is_scalar ($ argValue )) {
@@ -5111,6 +5114,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
51115114 }
51125115 }
51135116 } else {
5117+ /** @var array $arg */
51145118 if ($ arg ['type ' ] === 'Empty Argument ' && in_array ($ functionName , ['MIN ' , 'MINA ' , 'MAX ' , 'MAXA ' , 'IF ' ], true )) {
51155119 $ emptyArguments [] = false ;
51165120 $ args [] = $ arg ['value ' ] = 0 ;
@@ -5233,6 +5237,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
52335237 if ($ stack ->count () != 1 ) {
52345238 return $ this ->raiseFormulaError ('internal error ' );
52355239 }
5240+ /** @var array $output */
52365241 $ output = $ stack ->pop ();
52375242 $ output = $ output ['value ' ];
52385243
@@ -5285,6 +5290,7 @@ private function executeArrayComparison(mixed $operand1, mixed $operand2, string
52855290 foreach ($ operand1 as $ x => $ operandData ) {
52865291 $ this ->debugLog ->writeDebugLog ('Evaluating Comparison %s %s %s ' , $ this ->showValue ($ operandData ), $ operation , $ this ->showValue ($ operand2 ));
52875292 $ this ->executeBinaryComparisonOperation ($ operandData , $ operand2 , $ operation , $ stack );
5293+ /** @var array $r */
52885294 $ r = $ stack ->pop ();
52895295 $ result [$ x ] = $ r ['value ' ];
52905296 }
@@ -5293,6 +5299,7 @@ private function executeArrayComparison(mixed $operand1, mixed $operand2, string
52935299 foreach ($ operand2 as $ x => $ operandData ) {
52945300 $ this ->debugLog ->writeDebugLog ('Evaluating Comparison %s %s %s ' , $ this ->showValue ($ operand1 ), $ operation , $ this ->showValue ($ operandData ));
52955301 $ this ->executeBinaryComparisonOperation ($ operand1 , $ operandData , $ operation , $ stack );
5302+ /** @var array $r */
52965303 $ r = $ stack ->pop ();
52975304 $ result [$ x ] = $ r ['value ' ];
52985305 }
@@ -5304,6 +5311,7 @@ private function executeArrayComparison(mixed $operand1, mixed $operand2, string
53045311 foreach ($ operand1 as $ x => $ operandData ) {
53055312 $ this ->debugLog ->writeDebugLog ('Evaluating Comparison %s %s %s ' , $ this ->showValue ($ operandData ), $ operation , $ this ->showValue ($ operand2 [$ x ]));
53065313 $ this ->executeBinaryComparisonOperation ($ operandData , $ operand2 [$ x ], $ operation , $ stack , true );
5314+ /** @var array $r */
53075315 $ r = $ stack ->pop ();
53085316 $ result [$ x ] = $ r ['value ' ];
53095317 }
@@ -5495,7 +5503,7 @@ public function extractCellRange(string &$range = 'A1', ?Worksheet $worksheet =
54955503 $ worksheetName = $ worksheet ->getTitle ();
54965504
54975505 if (str_contains ($ range , '! ' )) {
5498- [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true );
5506+ [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true , true );
54995507 $ worksheet = ($ this ->spreadsheet === null ) ? null : $ this ->spreadsheet ->getSheetByName ($ worksheetName );
55005508 }
55015509
@@ -5557,7 +5565,7 @@ public function extractNamedRange(string &$range = 'A1', ?Worksheet $worksheet =
55575565
55585566 if ($ worksheet !== null ) {
55595567 if (str_contains ($ range , '! ' )) {
5560- [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true );
5568+ [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true , true );
55615569 $ worksheet = ($ this ->spreadsheet === null ) ? null : $ this ->spreadsheet ->getSheetByName ($ worksheetName );
55625570 }
55635571
0 commit comments