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            |   17 +++++++++++++++++
 sc/source/filter/excel/xetable.cxx                |    5 ++++-
 4 files changed, 21 insertions(+), 1 deletion(-)

New commits:
commit ad8c6d680dcf498a69542b43d4e13f9e9d3b903c
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:16:28 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]>
    (cherry picked from commit f20b05d40f628b00f2990d3dd895f3bb23d0ae17)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201034
    Reviewed-by: Caolán McNamara <[email protected]>

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 96d5af2fa8fd..38a7f7a06032 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -2542,6 +2542,23 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testTdf170565_empty_functions)
     assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[6]/x:c[2]/x:f", 
u"PRODUCT(,)");
 }
 
+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);
+
+    // 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 0c8a15ceeef1..d00d96ed5553 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