sc/qa/unit/data/xls/array_formula_with_macros.xls |binary
 sc/qa/unit/data/xls/formula_with_macros.xls       |binary
 sc/qa/unit/subsequent_export_test4.cxx            |   19 +++++++++++++++++++
 sc/source/filter/excel/xetable.cxx                |    5 ++++-
 4 files changed, 23 insertions(+), 1 deletion(-)

New commits:
commit 34340809cd9058c3bf3aac79695a81f55e53234c
Author:     Karthik Godha <[email protected]>
AuthorDate: Tue Feb 17 17:42:29 2026 +0530
Commit:     Caolán McNamara <[email protected]>
CommitDate: Thu Mar 5 17:15:40 2026 +0100

    XLSX: Properly handle macros in array formulas
    
    This is a regression from 108f4aa94b98ca6deffdc169068c175605d5ba67,
    XML_f element of array formulas containing macros was not closed in
    XLSX export.
    
    Change-Id: Iffd482ec23797bc64647a07e991220f373986d95
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199539
    Reviewed-by: Michael Stahl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201008
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/qa/unit/data/xls/array_formula_with_macros.xls 
b/sc/qa/unit/data/xls/array_formula_with_macros.xls
new file mode 100644
index 000000000000..81ca74d793c7
Binary files /dev/null and b/sc/qa/unit/data/xls/array_formula_with_macros.xls 
differ
diff --git a/sc/qa/unit/data/xls/formula_with_macros.xls 
b/sc/qa/unit/data/xls/formula_with_macros.xls
new file mode 100644
index 000000000000..25e149d13312
Binary files /dev/null and b/sc/qa/unit/data/xls/formula_with_macros.xls differ
diff --git a/sc/qa/unit/subsequent_export_test4.cxx 
b/sc/qa/unit/subsequent_export_test4.cxx
index 58ebc88fb01f..e948502ef588 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -1118,6 +1118,25 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testButtonFormControlXlsxExport)
     assertXPathNoAttribute(pDoc, "//x:controlPr", "macro");
 }
 
+CPPUNIT_TEST_FIXTURE(ScExportTest4, testMacrosInXLSX)
+{
+    // Array formula
+    createScDoc("xls/formula_with_macros.xls");
+    save(TestFilter::XLSX);
+    xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
+    CPPUNIT_ASSERT(pSheet);
+    assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]/x:c[1]/x:f", 0);
+
+    dispose();
+
+    // Regular formula
+    createScDoc("xls/array_formula_with_macros.xls");
+    save(TestFilter::XLSX);
+    pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
+    CPPUNIT_ASSERT(pSheet);
+    assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[2]/x:c[2]/x:f", 
u"");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/excel/xetable.cxx 
b/sc/source/filter/excel/xetable.cxx
index 4e329d8a9b65..984e63837f87 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1039,14 +1039,17 @@ void XclExpFormulaCell::SaveXml( XclExpXmlStream& rStrm 
)
                 rWorksheet->startElement(XML_f, XML_aca,
                                          ToPsz((mxTokArr && 
mxTokArr->IsVolatile())
                                                || (mxAddRec && 
mxAddRec->IsVolatile())));
+                bTagStarted = true;
             }
             rWorksheet->writeEscaped(XclXmlUtils::ToOUString(
                 rStrm.GetRoot().GetCompileFormulaContext(), mrScFmlaCell.aPos, 
&aTokenArray,
                 mrScFmlaCell.GetErrCode()));
-            rWorksheet->endElement(XML_f);
         }
     }
 
+    if (bTagStarted)
+        rWorksheet->endElement(XML_f);
+
     if( strcmp( sType, "inlineStr" ) == 0 )
     {
         rWorksheet->startElement(XML_is);

Reply via email to