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

New commits:
commit add5bec2321e6cc61fa92684e319461fd6158fac
Author:     Karthik Godha <[email protected]>
AuthorDate: Tue Feb 17 17:42:29 2026 +0530
Commit:     Xisco Fauli <[email protected]>
CommitDate: Fri Mar 6 08:59:26 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
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201072

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 1fafd5d6e1c1..a35cef74e230 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -2531,6 +2531,26 @@ 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);
+}
+
+CPPUNIT_TEST_FIXTURE(ScExportTest4, testMacrosInXLSX_Array)
+{
+    // Regular formula
+    createScDoc("xls/array_formula_with_macros.xls");
+    save(TestFilter::XLSX);
+    xmlDocUniquePtr 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 caa92c809096..efe89adcf5f1 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