sc/source/filter/excel/xename.cxx |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

New commits:
commit 1ad8b7dac03d7cdac00421d4f1e7cb12cc8734e4
Author:     Karthik Godha <[email protected]>
AuthorDate: Thu Jan 8 11:57:29 2026 +0530
Commit:     Michael Stahl <[email protected]>
CommitDate: Wed Jan 14 13:51:28 2026 +0100

    XLS->XLSX: Invalid name attribute in 'definedName'
    
    In XLSX export definedName element's "name" attribute can't contain
    spaces in its string. Replace all spaces with underscores.
    
    bug document: fdo49673-1.xls
    
    Change-Id: Iece104a044d7880ba767df6dc0e1c016ba683bbf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196792
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit 0c90176f8f0c80e0707f058ba83a4158bc10dbf2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197158

diff --git a/sc/source/filter/excel/xename.cxx 
b/sc/source/filter/excel/xename.cxx
index 2312a7920613..c83eb66373d0 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -333,6 +333,14 @@ void XclExpName::SaveXml( XclExpXmlStream& rStrm )
     // Sheets where IsExportTab is not true are not exported, so use mnXclTab
     // (1 based) to get the sheetid as of the exported document's perspective.
     SCTAB nXlsxTab = mnXclTab - 1;
+    OUString sName = maOrigName;
+    if (sName.indexOf(' ') != -1)
+    {
+        sName = sName.replace(' ', '_');
+        SAL_WARN("sc.filter",
+                 "'" << maOrigName << "' is an invalid name, using '" << sName 
<< "' instead.");
+    }
+
     rWorkbook->startElement( XML_definedName,
             // OOXTODO: XML_comment, "",
             // OOXTODO: XML_customMenu, "",
@@ -342,7 +350,7 @@ void XclExpName::SaveXml( XclExpXmlStream& rStrm )
             // OOXTODO: XML_help, "",
             XML_hidden, ToPsz( ::get_flag( mnFlags, EXC_NAME_HIDDEN ) ),
             XML_localSheetId, sax_fastparser::UseIf(OString::number(nXlsxTab), 
mnScTab != SCTAB_GLOBAL),
-            XML_name, maOrigName.toUtf8(),
+            XML_name, sName.toUtf8(),
             // OOXTODO: XML_publishToServer, "",
             // OOXTODO: XML_shortcutKey, "",
             // OOXTODO: XML_statusBar, "",

Reply via email to