sc/qa/unit/data/ods/tdf170292.ods |binary sc/qa/unit/subsequent_export_test3.cxx | 13 +++++++++++++ sc/source/core/tool/compiler.cxx | 6 +++++- sc/source/filter/excel/xename.cxx | 7 +++++++ 4 files changed, 25 insertions(+), 1 deletion(-)
New commits: commit bcd9517e69cfcd3dbab16878194bdabfa43a65cf Author: Karthik Godha <[email protected]> AuthorDate: Sun Jan 11 09:50:10 2026 +0530 Commit: Karthik Godha <[email protected]> CommitDate: Mon Feb 16 01:12:35 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]> (cherry picked from commit 8e144c9f5cb322d51f2bd1441c26619dd1b255b6) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199417 Tested-by: Jenkins Reviewed-by: Karthik Godha <[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 3bd62d693fc9..45d09cf373bb 100644 --- a/sc/qa/unit/subsequent_export_test3.cxx +++ b/sc/qa/unit/subsequent_export_test3.cxx @@ -2077,6 +2077,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 ef6e84621cbd..3722165a1cfc 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -5852,7 +5852,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, "",
