@@ -69,8 +69,6 @@ class Calculation
6969
7070 /**
7171 * Instance of this class.
72- *
73- * @var ?Calculation
7472 */
7573 private static ?Calculation $ instance = null ;
7674
@@ -3272,10 +3270,8 @@ private static function translateFormula(array $from, array $to, string $formula
32723270 return $ formula ;
32733271 }
32743272
3275- /** @var ?array */
32763273 private static ?array $ functionReplaceFromExcel ;
32773274
3278- /** @var ?array */
32793275 private static ?array $ functionReplaceToLocale ;
32803276
32813277 /**
@@ -3321,10 +3317,8 @@ public function translateFormulaToLocale(string $formula): string
33213317 );
33223318 }
33233319
3324- /** @var ?array */
33253320 private static ?array $ functionReplaceFromLocale ;
33263321
3327- /** @var ?array */
33283322 private static ?array $ functionReplaceToExcel ;
33293323
33303324 /**
@@ -5087,9 +5081,10 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
50875081 if ($ cell === null || $ pCellWorksheet === null ) {
50885082 return $ this ->raiseFormulaError ("undefined name ' $ token' " );
50895083 }
5084+ $ specifiedWorksheet = trim ($ matches [2 ], "' " );
50905085
50915086 $ this ->debugLog ->writeDebugLog ('Evaluating Defined Name %s ' , $ definedName );
5092- $ namedRange = DefinedName::resolveName ($ definedName , $ pCellWorksheet );
5087+ $ namedRange = DefinedName::resolveName ($ definedName , $ pCellWorksheet, $ specifiedWorksheet );
50935088 // If not Defined Name, try as Table.
50945089 if ($ namedRange === null && $ this ->spreadsheet !== null ) {
50955090 $ table = $ this ->spreadsheet ->getTableByName ($ definedName );
@@ -5114,7 +5109,7 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
51145109 return $ this ->raiseFormulaError ("undefined name ' $ definedName' " );
51155110 }
51165111
5117- $ result = $ this ->evaluateDefinedName ($ cell , $ namedRange , $ pCellWorksheet , $ stack );
5112+ $ result = $ this ->evaluateDefinedName ($ cell , $ namedRange , $ pCellWorksheet , $ stack, $ specifiedWorksheet !== '' );
51185113 if (isset ($ storeKey )) {
51195114 $ branchStore [$ storeKey ] = $ result ;
51205115 }
@@ -5593,10 +5588,10 @@ private function addCellReference(array $args, bool $passCellReference, array|st
55935588 return $ args ;
55945589 }
55955590
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
55975592 {
55985593 $ definedNameScope = $ namedRange ->getScope ();
5599- if ($ definedNameScope !== null && $ definedNameScope !== $ cellWorksheet ) {
5594+ if ($ definedNameScope !== null && $ definedNameScope !== $ cellWorksheet && ! $ ignoreScope ) {
56005595 // The defined name isn't in our current scope, so #REF
56015596 $ result = ExcelError::REF ();
56025597 $ stack ->push ('Error ' , $ result , $ namedRange ->getName ());
0 commit comments