@@ -69,8 +69,6 @@ class Calculation
69
69
70
70
/**
71
71
* Instance of this class.
72
- *
73
- * @var ?Calculation
74
72
*/
75
73
private static ?Calculation $ instance = null ;
76
74
@@ -3272,10 +3270,8 @@ private static function translateFormula(array $from, array $to, string $formula
3272
3270
return $ formula ;
3273
3271
}
3274
3272
3275
- /** @var ?array */
3276
3273
private static ?array $ functionReplaceFromExcel ;
3277
3274
3278
- /** @var ?array */
3279
3275
private static ?array $ functionReplaceToLocale ;
3280
3276
3281
3277
/**
@@ -3321,10 +3317,8 @@ public function translateFormulaToLocale(string $formula): string
3321
3317
);
3322
3318
}
3323
3319
3324
- /** @var ?array */
3325
3320
private static ?array $ functionReplaceFromLocale ;
3326
3321
3327
- /** @var ?array */
3328
3322
private static ?array $ functionReplaceToExcel ;
3329
3323
3330
3324
/**
@@ -5087,9 +5081,10 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
5087
5081
if ($ cell === null || $ pCellWorksheet === null ) {
5088
5082
return $ this ->raiseFormulaError ("undefined name ' $ token' " );
5089
5083
}
5084
+ $ specifiedWorksheet = trim ($ matches [2 ], "' " );
5090
5085
5091
5086
$ this ->debugLog ->writeDebugLog ('Evaluating Defined Name %s ' , $ definedName );
5092
- $ namedRange = DefinedName::resolveName ($ definedName , $ pCellWorksheet );
5087
+ $ namedRange = DefinedName::resolveName ($ definedName , $ pCellWorksheet, $ specifiedWorksheet );
5093
5088
// If not Defined Name, try as Table.
5094
5089
if ($ namedRange === null && $ this ->spreadsheet !== null ) {
5095
5090
$ table = $ this ->spreadsheet ->getTableByName ($ definedName );
@@ -5114,7 +5109,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
5114
5109
return $ this ->raiseFormulaError ("undefined name ' $ definedName' " );
5115
5110
}
5116
5111
5117
- $ result = $ this ->evaluateDefinedName ($ cell , $ namedRange , $ pCellWorksheet , $ stack );
5112
+ $ result = $ this ->evaluateDefinedName ($ cell , $ namedRange , $ pCellWorksheet , $ stack, $ specifiedWorksheet !== '' );
5118
5113
if (isset ($ storeKey )) {
5119
5114
$ branchStore [$ storeKey ] = $ result ;
5120
5115
}
@@ -5593,10 +5588,10 @@ private function addCellReference(array $args, bool $passCellReference, array|st
5593
5588
return $ args ;
5594
5589
}
5595
5590
5596
- private function evaluateDefinedName (Cell $ cell , DefinedName $ namedRange , Worksheet $ cellWorksheet , Stack $ stack ): mixed
5591
+ private function evaluateDefinedName (Cell $ cell , DefinedName $ namedRange , Worksheet $ cellWorksheet , Stack $ stack, bool $ ignoreScope = false ): mixed
5597
5592
{
5598
5593
$ definedNameScope = $ namedRange ->getScope ();
5599
- if ($ definedNameScope !== null && $ definedNameScope !== $ cellWorksheet ) {
5594
+ if ($ definedNameScope !== null && $ definedNameScope !== $ cellWorksheet && ! $ ignoreScope ) {
5600
5595
// The defined name isn't in our current scope, so #REF
5601
5596
$ result = ExcelError::REF ();
5602
5597
$ stack ->push ('Error ' , $ result , $ namedRange ->getName ());
0 commit comments