sc/qa/unit/data/ods/tdf170292.ods      |binary
 sc/qa/unit/subsequent_export_test3.cxx |   15 ++++++++++++++-
 sc/source/core/tool/compiler.cxx       |    6 +++++-
 sc/source/filter/excel/xename.cxx      |    7 +++++++
 4 files changed, 26 insertions(+), 2 deletions(-)

New commits:
commit 8e144c9f5cb322d51f2bd1441c26619dd1b255b6
Author:     Karthik Godha <[email protected]>
AuthorDate: Sun Jan 11 09:50:10 2026 +0530
Commit:     Michael Stahl <[email protected]>
CommitDate: Thu Jan 15 16:43:38 2026 +0100

    tdf#170292: XLSX - cell references in definedName
    
    Valid cell references can't be used in definedNames, add underscore to
    definedNames which are valid cell references
    
    Change-Id: Iaa3e415ee644aa56c3462245b11038993e16a971
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197004
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>
    (cherry picked from commit 2b1b071c113a53710032713340735d421e536b97)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197321
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sc/qa/unit/data/ods/tdf170292.ods 
b/sc/qa/unit/data/ods/tdf170292.ods
new file mode 100644
index 000000000000..6078f1673b86
Binary files /dev/null and b/sc/qa/unit/data/ods/tdf170292.ods differ
diff --git a/sc/qa/unit/subsequent_export_test3.cxx 
b/sc/qa/unit/subsequent_export_test3.cxx
index ae7ea8b32a3d..721c8c5edc34 100644
--- a/sc/qa/unit/subsequent_export_test3.cxx
+++ b/sc/qa/unit/subsequent_export_test3.cxx
@@ -2072,7 +2072,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf170249)
 {
     createScDoc("ods/tdf170249.ods");
 
-    save(u"Calc Office Open XML"_ustr);
+    save(TestFilter::XLSX);
     xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
     CPPUNIT_ASSERT(pSheet);
 
@@ -2080,6 +2080,19 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf170249)
                        u"INDEX($B2:$XFD2, 1, 2)");
 }
 
+CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf170292)
+{
+    createScDoc("ods/tdf170292.ods");
+
+    save(TestFilter::XLSX);
+    xmlDocUniquePtr pSheet = parseExport(u"xl/workbook.xml"_ustr);
+    CPPUNIT_ASSERT(pSheet);
+
+    assertXPath(pSheet, "/x:workbook/x:definedNames/x:definedName[1]", "name", 
u"_cat1");
+    assertXPathContent(pSheet, "/x:workbook/x:definedNames/x:definedName[2]",
+                       u"OFFSET(_cat1,0,2,,)");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 7845de51468c..e610e758a892 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -5807,7 +5807,11 @@ void ScCompiler::CreateStringFromIndex( OUStringBuffer& 
rBuffer, const FormulaTo
                     aBuffer.append("[0]"
                         + 
OUStringChar(pConv->getSpecialSymbol(ScCompiler::Convention::SHEET_SEPARATOR)));
                 }
-                aBuffer.append(pData->GetName());
+                OUString sName = pData->GetName();
+                // If the name is a valid reference then add underscore to the 
name
+                if (ScAddress().Parse(sName, rDoc, FormulaGrammar::CONV_XL_A1) 
& ScRefFlags::VALID)
+                    sName = "_" + sName;
+                aBuffer.append(sName);
             }
         }
         break;
diff --git a/sc/source/filter/excel/xename.cxx 
b/sc/source/filter/excel/xename.cxx
index c83eb66373d0..092ab5e53e7f 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -340,6 +340,13 @@ void XclExpName::SaveXml( XclExpXmlStream& rStrm )
         SAL_WARN("sc.filter",
                  "'" << maOrigName << "' is an invalid name, using '" << sName 
<< "' instead.");
     }
+    else
+    {
+        // If the name is a valid reference then add underscore to the name
+        if (ScAddress().Parse(sName, GetDoc(), 
::formula::FormulaGrammar::CONV_XL_A1)
+            & ScRefFlags::VALID)
+            sName = "_" + sName;
+    }
 
     rWorkbook->startElement( XML_definedName,
             // OOXTODO: XML_comment, "",

Reply via email to