@@ -35,7 +35,7 @@ class Calculation extends CalculationLocale
3535 // Opening bracket
3636 const CALCULATION_REGEXP_OPENBRACE = '\( ' ;
3737 // Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it)
38- const CALCULATION_REGEXP_FUNCTION = '@?(?:_xlfn\.)?(?:_xlws\.)?([\p{L}][\p{L}\p{N}\.]*)[\s]*\( ' ;
38+ const CALCULATION_REGEXP_FUNCTION = '@?(?:_xlfn\.)?(?:_xlws\.)?((?:__xludf\.)? [\p{L}][\p{L}\p{N}\.]*)[\s]*\( ' ;
3939 // Cell reference (cell or range of cells, with or without a sheet reference)
4040 const CALCULATION_REGEXP_CELLREF = '((([^\s,!&%^\/\*\+<>=:`-]*)|( \'(?:[^ \']| \'[^!])+? \')|(\"(?:[^\"]|\"[^!])+?\"))!)?\$?\b([a-z]{1,3})\$?(\d{1,7})(?![\w.]) ' ;
4141 // Used only to detect spill operator #
@@ -1738,6 +1738,16 @@ private function processTokenStack(false|array $tokens, ?string $cellID = null,
17381738 break ;
17391739 // Binary Operators
17401740 case ': ' : // Range
1741+ if ($ operand1Data ['type ' ] === 'Error ' ) {
1742+ $ stack ->push ($ operand1Data ['type ' ], $ operand1Data ['value ' ], null );
1743+
1744+ break ;
1745+ }
1746+ if ($ operand2Data ['type ' ] === 'Error ' ) {
1747+ $ stack ->push ($ operand2Data ['type ' ], $ operand2Data ['value ' ], null );
1748+
1749+ break ;
1750+ }
17411751 if ($ operand1Data ['type ' ] === 'Defined Name ' ) {
17421752 /** @var array{reference: string} $operand1Data */
17431753 if (preg_match ('/$ ' . self ::CALCULATION_REGEXP_DEFINEDNAME . '^/mui ' , $ operand1Data ['reference ' ]) !== false && $ this ->spreadsheet !== null ) {
@@ -2101,6 +2111,13 @@ private function processTokenStack(false|array $tokens, ?string $cellID = null,
21012111 $ nextArg = '' ;
21022112 }
21032113 }
2114+ } elseif (($ arg ['type ' ] ?? '' ) === 'Error ' ) {
2115+ $ argValue = $ arg ['value ' ];
2116+ if (is_scalar ($ argValue )) {
2117+ $ nextArg = $ argValue ;
2118+ } elseif (empty ($ argValue )) {
2119+ $ nextArg = '' ;
2120+ }
21042121 }
21052122 $ args [] = $ nextArg ;
21062123 if ($ functionName !== 'MKMATRIX ' ) {
@@ -2231,11 +2248,13 @@ private function processTokenStack(false|array $tokens, ?string $cellID = null,
22312248 }
22322249 }
22332250 if ($ namedRange === null ) {
2234- return $ this ->raiseFormulaError ("undefined name ' $ definedName' " );
2251+ $ result = ExcelError::NAME ();
2252+ $ stack ->push ('Error ' , $ result , null );
2253+ $ this ->debugLog ->writeDebugLog ("Error $ result " );
2254+ } else {
2255+ $ result = $ this ->evaluateDefinedName ($ cell , $ namedRange , $ pCellWorksheet , $ stack , $ specifiedWorksheet !== '' );
22352256 }
22362257
2237- $ result = $ this ->evaluateDefinedName ($ cell , $ namedRange , $ pCellWorksheet , $ stack , $ specifiedWorksheet !== '' );
2238-
22392258 if (isset ($ storeKey )) {
22402259 $ branchStore [$ storeKey ] = $ result ;
22412260 }
@@ -2501,6 +2520,8 @@ protected function raiseFormulaError(string $errorMessage, int $code = 0, ?Throw
25012520 $ this ->formulaError = $ errorMessage ;
25022521 $ this ->cyclicReferenceStack ->clear ();
25032522 $ suppress = $ this ->suppressFormulaErrors ;
2523+ $ suppressed = $ suppress ? ' $suppressed ' : '' ;
2524+ $ this ->debugLog ->writeDebugLog ("Raise Error $ suppressed $ errorMessage " );
25042525 if (!$ suppress ) {
25052526 throw new Exception ($ errorMessage , $ code , $ exception );
25062527 }
@@ -2808,7 +2829,13 @@ private function evaluateDefinedName(Cell $cell, DefinedName $namedRange, Worksh
28082829 $ this ->debugLog ->writeDebugLog ('Evaluation Result for Named %s %s is %s ' , $ definedNameType , $ namedRange ->getName (), $ this ->showTypeDetails ($ result ));
28092830 }
28102831
2811- $ stack ->push ('Defined Name ' , $ result , $ namedRange ->getName ());
2832+ $ y = $ namedRange ->getWorksheet ()?->getTitle();
2833+ $ x = $ namedRange ->getLocalOnly ();
2834+ if ($ x && $ y !== null ) {
2835+ $ stack ->push ('Defined Name ' , $ result , "' $ y'! " . $ namedRange ->getName ());
2836+ } else {
2837+ $ stack ->push ('Defined Name ' , $ result , $ namedRange ->getName ());
2838+ }
28122839
28132840 return $ result ;
28142841 }
0 commit comments