@@ -4408,7 +4408,9 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
4408
4408
if ($ rangeWS1 !== '' ) {
4409
4409
$ rangeWS1 .= '! ' ;
4410
4410
}
4411
- $ rangeSheetRef = trim ($ rangeSheetRef , "' " );
4411
+ if (str_starts_with ($ rangeSheetRef , "' " )) {
4412
+ $ rangeSheetRef = Worksheet::unApostrophizeTitle ($ rangeSheetRef );
4413
+ }
4412
4414
[$ rangeWS2 , $ val ] = Worksheet::extractSheetTitle ($ val , true );
4413
4415
if ($ rangeWS2 !== '' ) {
4414
4416
$ rangeWS2 .= '! ' ;
@@ -4424,11 +4426,10 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool
4424
4426
if (ctype_digit ($ val ) && $ val <= 1048576 ) {
4425
4427
// Row range
4426
4428
$ stackItemType = 'Row Reference ' ;
4427
- /** @var int $valx */
4428
4429
$ valx = $ val ;
4429
4430
$ endRowColRef = ($ refSheet !== null ) ? $ refSheet ->getHighestDataColumn ($ valx ) : AddressRange::MAX_COLUMN ; // Max 16,384 columns for Excel2007
4430
4431
$ val = "{$ rangeWS2 }{$ endRowColRef }{$ val }" ;
4431
- } elseif (ctype_alpha ($ val ) && is_string ( $ val ) && strlen ($ val ) <= 3 ) {
4432
+ } elseif (ctype_alpha ($ val ) && strlen ($ val ) <= 3 ) {
4432
4433
// Column range
4433
4434
$ stackItemType = 'Column Reference ' ;
4434
4435
$ 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
4562
4563
4563
4564
while (($ op = $ stack ->pop ()) !== null ) {
4564
4565
// pop everything off the stack and push onto output
4565
- if (( is_array ( $ op) && $ op ['value ' ] == '( ' ) ) {
4566
+ if ($ op ['value ' ] == '( ' ) {
4566
4567
return $ this ->raiseFormulaError ("Formula Error: Expecting ')' " ); // if there are any opening braces on the stack, then braces were unbalanced
4567
4568
}
4568
4569
$ output [] = $ op ;
@@ -4766,18 +4767,18 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
4766
4767
}
4767
4768
}
4768
4769
if (str_contains ($ operand1Data ['reference ' ] ?? '' , '! ' )) {
4769
- [$ sheet1 , $ operand1Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand1Data ['reference ' ], true );
4770
+ [$ sheet1 , $ operand1Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand1Data ['reference ' ], true , true );
4770
4771
} else {
4771
4772
$ sheet1 = ($ pCellWorksheet !== null ) ? $ pCellWorksheet ->getTitle () : '' ;
4772
4773
}
4773
4774
$ sheet1 ??= '' ;
4774
4775
4775
- [$ sheet2 , $ operand2Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand2Data ['reference ' ], true );
4776
+ [$ sheet2 , $ operand2Data ['reference ' ]] = Worksheet::extractSheetTitle ($ operand2Data ['reference ' ], true , true );
4776
4777
if (empty ($ sheet2 )) {
4777
4778
$ sheet2 = $ sheet1 ;
4778
4779
}
4779
4780
4780
- if (trim ( $ sheet1, " ' " ) === trim ( $ sheet2, " ' " ) ) {
4781
+ if ($ sheet1 === $ sheet2 ) {
4781
4782
if ($ operand1Data ['reference ' ] === null && $ cell !== null ) {
4782
4783
if (is_array ($ operand1Data ['value ' ])) {
4783
4784
$ operand1Data ['reference ' ] = $ cell ->getCoordinate ();
@@ -4819,7 +4820,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
4819
4820
if ($ breakNeeded ) {
4820
4821
break ;
4821
4822
}
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
4823
4824
if ($ pCellParent !== null && $ this ->spreadsheet !== null ) {
4824
4825
$ cellValue = $ this ->extractCellRange ($ cellRef , $ this ->spreadsheet ->getSheetByName ($ sheet1 ), false );
4825
4826
} else {
@@ -4917,8 +4918,8 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
4917
4918
$ this ->debugLog ->writeDebugLog ('Evaluation Result is %s ' , $ this ->showTypeDetails ($ cellIntersect ));
4918
4919
$ stack ->push ('Error ' , ExcelError::null (), null );
4919
4920
} 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
4922
4923
$ this ->debugLog ->writeDebugLog ('Evaluation Result is %s ' , $ this ->showTypeDetails ($ cellIntersect ));
4923
4924
$ stack ->push ('Value ' , $ cellIntersect , $ cellRef );
4924
4925
}
@@ -5058,6 +5059,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
5058
5059
}
5059
5060
5060
5061
$ functionName = $ matches [1 ];
5062
+ /** @var array $argCount */
5061
5063
$ argCount = $ stack ->pop ();
5062
5064
$ argCount = $ argCount ['value ' ];
5063
5065
if ($ functionName !== 'MKMATRIX ' ) {
@@ -5088,9 +5090,10 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
5088
5090
&& (isset (self ::$ phpSpreadsheetFunctions [$ functionName ]['passByReference ' ][$ a ]))
5089
5091
&& (self ::$ phpSpreadsheetFunctions [$ functionName ]['passByReference ' ][$ a ])
5090
5092
) {
5093
+ /** @var array $arg */
5091
5094
if ($ arg ['reference ' ] === null ) {
5092
5095
$ nextArg = $ cellID ;
5093
- if ($ functionName === 'ISREF ' && is_array ( $ arg ) && ($ arg ['type ' ] ?? '' ) === 'Value ' ) {
5096
+ if ($ functionName === 'ISREF ' && ($ arg ['type ' ] ?? '' ) === 'Value ' ) {
5094
5097
if (array_key_exists ('value ' , $ arg )) {
5095
5098
$ argValue = $ arg ['value ' ];
5096
5099
if (is_scalar ($ argValue )) {
@@ -5111,6 +5114,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
5111
5114
}
5112
5115
}
5113
5116
} else {
5117
+ /** @var array $arg */
5114
5118
if ($ arg ['type ' ] === 'Empty Argument ' && in_array ($ functionName , ['MIN ' , 'MINA ' , 'MAX ' , 'MAXA ' , 'IF ' ], true )) {
5115
5119
$ emptyArguments [] = false ;
5116
5120
$ args [] = $ arg ['value ' ] = 0 ;
@@ -5233,6 +5237,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
5233
5237
if ($ stack ->count () != 1 ) {
5234
5238
return $ this ->raiseFormulaError ('internal error ' );
5235
5239
}
5240
+ /** @var array $output */
5236
5241
$ output = $ stack ->pop ();
5237
5242
$ output = $ output ['value ' ];
5238
5243
@@ -5285,6 +5290,7 @@ private function executeArrayComparison(mixed $operand1, mixed $operand2, string
5285
5290
foreach ($ operand1 as $ x => $ operandData ) {
5286
5291
$ this ->debugLog ->writeDebugLog ('Evaluating Comparison %s %s %s ' , $ this ->showValue ($ operandData ), $ operation , $ this ->showValue ($ operand2 ));
5287
5292
$ this ->executeBinaryComparisonOperation ($ operandData , $ operand2 , $ operation , $ stack );
5293
+ /** @var array $r */
5288
5294
$ r = $ stack ->pop ();
5289
5295
$ result [$ x ] = $ r ['value ' ];
5290
5296
}
@@ -5293,6 +5299,7 @@ private function executeArrayComparison(mixed $operand1, mixed $operand2, string
5293
5299
foreach ($ operand2 as $ x => $ operandData ) {
5294
5300
$ this ->debugLog ->writeDebugLog ('Evaluating Comparison %s %s %s ' , $ this ->showValue ($ operand1 ), $ operation , $ this ->showValue ($ operandData ));
5295
5301
$ this ->executeBinaryComparisonOperation ($ operand1 , $ operandData , $ operation , $ stack );
5302
+ /** @var array $r */
5296
5303
$ r = $ stack ->pop ();
5297
5304
$ result [$ x ] = $ r ['value ' ];
5298
5305
}
@@ -5304,6 +5311,7 @@ private function executeArrayComparison(mixed $operand1, mixed $operand2, string
5304
5311
foreach ($ operand1 as $ x => $ operandData ) {
5305
5312
$ this ->debugLog ->writeDebugLog ('Evaluating Comparison %s %s %s ' , $ this ->showValue ($ operandData ), $ operation , $ this ->showValue ($ operand2 [$ x ]));
5306
5313
$ this ->executeBinaryComparisonOperation ($ operandData , $ operand2 [$ x ], $ operation , $ stack , true );
5314
+ /** @var array $r */
5307
5315
$ r = $ stack ->pop ();
5308
5316
$ result [$ x ] = $ r ['value ' ];
5309
5317
}
@@ -5495,7 +5503,7 @@ public function extractCellRange(string &$range = 'A1', ?Worksheet $worksheet =
5495
5503
$ worksheetName = $ worksheet ->getTitle ();
5496
5504
5497
5505
if (str_contains ($ range , '! ' )) {
5498
- [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true );
5506
+ [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true , true );
5499
5507
$ worksheet = ($ this ->spreadsheet === null ) ? null : $ this ->spreadsheet ->getSheetByName ($ worksheetName );
5500
5508
}
5501
5509
@@ -5557,7 +5565,7 @@ public function extractNamedRange(string &$range = 'A1', ?Worksheet $worksheet =
5557
5565
5558
5566
if ($ worksheet !== null ) {
5559
5567
if (str_contains ($ range , '! ' )) {
5560
- [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true );
5568
+ [$ worksheetName , $ range ] = Worksheet::extractSheetTitle ($ range , true , true );
5561
5569
$ worksheet = ($ this ->spreadsheet === null ) ? null : $ this ->spreadsheet ->getSheetByName ($ worksheetName );
5562
5570
}
5563
5571
0 commit comments