sc/source/core/tool/compiler.cxx |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

New commits:
commit 6868442d97773bccabeb50b12b0f373a262933d0
Author:     Karthik Godha <[email protected]>
AuthorDate: Mon Feb 9 14:56:56 2026 +0530
Commit:     Michael Stahl <[email protected]>
CommitDate: Tue Feb 10 13:51:30 2026 +0100

    XLSX: Properly handle quotes in 3D references
    
    This is related to 472f17d203207f1ef9d75ecfc9facda2d5f43384.
    
    bug-document: forum-mso-en4-254252.xls
    Change-Id: I748ea3aa920d560085398aab08cd35deeb2818d3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198963
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 94a56b3a7385..e2f4e8ced711 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2015,18 +2015,23 @@ void ScCompiler::FormExcelSheetRange( OUStringBuffer& 
rBuf, sal_Int32 nQuotePos,
     OUString aEndTabName(rEndTabName);
     if (nQuotePos < rBuf.getLength())
     {
+        const bool bQuoted1 = rBuf[nQuotePos] == '\'';
         const bool bQuoted2 = (!aEndTabName.isEmpty() && aEndTabName[0] == 
'\'');
-        if (bQuoted2)
-            aEndTabName = aEndTabName.subView(1);   //  Sheet2'
-        if (rBuf[nQuotePos] == '\'')                // 'Sheet1'
+        if (bQuoted1 && bQuoted2) // Both sheets are quoted
         {
-            const sal_Int32 nLast = rBuf.getLength() - 1;
-            if (rBuf[nLast] == '\'')
-                rBuf.remove(nLast, 1);              // 'Sheet1
+            rBuf.remove(rBuf.getLength() - 1, 1);
+            aEndTabName = aEndTabName.subView(1);
         }
-        else if (bQuoted2)                          //  Sheet1
+        else if (bQuoted1) // Only Sheet1 is quoted
         {
-            rBuf.insert(nQuotePos, '\'');           // 'Sheet1
+            rBuf.remove(rBuf.getLength() - 1, 1);
+            if (!aEndTabName.isEmpty())
+                aEndTabName = aEndTabName + "\'";
+        }
+        else if (bQuoted2) // Only Sheet2 is quoted
+        {
+            rBuf.insert(nQuotePos, '\'');
+            aEndTabName = aEndTabName.subView(1);
         }
     }
     rBuf.append( ':' );

Reply via email to