This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch odf13-devel
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 47115ea3a02e7718668cd47df0388330b324dd77
Author: Jim Jagielski <[email protected]>
AuthorDate: Fri Oct 30 13:47:46 2026 -0400

    formula, sc: Write a top-level range list as a union and a broken reference 
as [#REF!] in ODFF, and read [#REF!]
---
 main/formula/source/core/api/FormulaCompiler.cxx | 16 +++++++++++
 main/sc/source/core/tool/compiler.cxx            | 35 +++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/main/formula/source/core/api/FormulaCompiler.cxx 
b/main/formula/source/core/api/FormulaCompiler.cxx
index bb40ce20d2..a60d450ffa 100644
--- a/main/formula/source/core/api/FormulaCompiler.cxx
+++ b/main/formula/source/core/api/FormulaCompiler.cxx
@@ -1488,8 +1488,24 @@ void FormulaCompiler::CreateStringFromTokenArray( 
rtl::OUStringBuffer& rBuffer )
     if ( pArr->IsRecalcModeForced() )
         rBuffer.append(sal_Unicode('='));
     FormulaToken* t = pArr->First();
+    sal_uInt16 nOpen = 0;
     while( t )
+    {
+        OpCode eOp = t->GetOpCode();
+        if (eOp == ocOpen)
+            ++nOpen;
+        else if (eOp == ocClose && nOpen)
+            --nOpen;
+        else if (bODFF && eOp == ocSep && !nOpen)
+        {
+            // The Excel import joins ranges with ocSep; outside parentheses 
ODFF has no
+            // separator, the union operator is meant.
+            rBuffer.append( mxSymbols->getSymbol( ocUnion));
+            t = pArr->Next();
+            continue;
+        }
         t = CreateStringFromToken( rBuffer, t, sal_True );
+    }
 
     if (pSaveArr != pArr)
     {
diff --git a/main/sc/source/core/tool/compiler.cxx 
b/main/sc/source/core/tool/compiler.cxx
index e5b3798807..80ba186543 100644
--- a/main/sc/source/core/tool/compiler.cxx
+++ b/main/sc/source/core/tool/compiler.cxx
@@ -885,6 +885,21 @@ struct ConventionOOO_A1 : public Convention_A1
         aRef.Ref1.CalcAbsIfRel( rComp.GetPos() );
         if( !bSingleRef )
             aRef.Ref2.CalcAbsIfRel( rComp.GetPos() );
+        if (bODF)
+        {
+            // OpenFormula has no spelling for a part of a reference that was 
deleted: the whole reference is [#REF!]
+            bool bBroken = aRef.Ref1.IsColDeleted() || 
aRef.Ref1.IsRowDeleted() ||
+                    (aRef.Ref1.IsFlag3D() && aRef.Ref1.IsTabDeleted());
+            if (!bSingleRef)
+                bBroken = bBroken || aRef.Ref2.IsColDeleted() || 
aRef.Ref2.IsRowDeleted() ||
+                        ((aRef.Ref2.IsFlag3D() || aRef.Ref2.nTab != 
aRef.Ref1.nTab) && aRef.Ref2.IsTabDeleted());
+            if (bBroken)
+            {
+                rBuffer.append(ScGlobal::GetRscString(STR_NO_REF_TABLE));
+                rBuffer.append(sal_Unicode(']'));
+                return;
+            }
+        }
         if( aRef.Ref1.IsFlag3D() )
         {
             if (aRef.Ref1.IsTabDeleted())
@@ -2290,7 +2305,8 @@ Label_MaskStateMachine:
                     bool bAddToSymbol = true;
                     if ((nMask & SC_COMPILER_C_ODF_RBRACKET) && !(nRefInName & 
kOpen))
                     {
-                        DBG_ASSERT( nRefInName & (kPast | kDefName),
+                        DBG_ASSERT( (nRefInName & (kPast | kDefName)) || (pSym 
- cSymbol == 5 &&
+                                cSymbol[0] == '#' && cSymbol[1] == 'R' && 
cSymbol[2] == 'E' && cSymbol[3] == 'F' && cSymbol[4] == '!'),
                                 "ScCompiler::NextSymbol: reference: "
                                 "closing bracket ']' without prior sheet name 
separator '.' violates ODF spec");
                         // eaten, not added to pSym
@@ -3580,6 +3596,23 @@ sal_Bool ScCompiler::NextNewToken( bool bInArray )
     if (mnPredetectedReference)
     {
         String aStr( cSymbol);
+        if (aStr.EqualsAscii( "#REF!"))
+        {
+            // [#REF!], what ODF writes for a broken reference, is a deleted 
reference
+            ScSingleRefData aRef;
+            aRef.InitMembers();
+            aRef.InitAddress( MAXCOL+1, MAXROW+1, MAXTAB+3);    // out of 
range, as for an invalid reference
+            aRef.SetColRel( sal_True);
+            aRef.SetRowRel( sal_True);
+            aRef.SetColDeleted( sal_True);
+            aRef.SetRowDeleted( sal_True);
+            aRef.SetTabDeleted( sal_True);
+            aRef.CalcRelFromAbs( aPos);
+            ScRawToken aToken;
+            aToken.SetSingleReference( aRef);
+            pRawToken = aToken.Clone();
+            return true;
+        }
         if (!IsPredetectedReference( aStr) && !IsExternalNamedRange( aStr))
         {
             /* TODO: it would be nice to generate a #REF! error here, which

Reply via email to