formula/source/core/api/token.cxx | 21 +++++++++++++++++++-- sc/qa/unit/data/ods/tdf170565_empty_functions.ods |binary sc/qa/unit/subsequent_export_test5.cxx | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-)
New commits: commit 8ea0c3678ffa87af77566add850b950361d17301 Author: Karthik Godha <[email protected]> AuthorDate: Fri Feb 13 18:02:30 2026 +0530 Commit: Aron Budea <[email protected]> CommitDate: Tue Feb 24 23:35:56 2026 +0100 tdf#170565: Handle empty aggregate functions in XLSX This is an extension of 3cbf4957d33c7414b5cd02481136679b5c6a834e, handle AVERAGE, COUNT and PRODUCT functions without parameters in XLSX Change-Id: I6c669e58f4d1ca87b557d11cd16cfd284531360f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199345 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Aron Budea <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200162 Tested-by: Jenkins diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index 9c41f2986c9f..ceebc87e9ec5 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -1077,9 +1077,12 @@ inline bool MissingConventionOOXML::isRewriteNeeded( OpCode eOp ) { switch (eOp) { + case ocAverage: + case ocCount: case ocIf: case ocMax: case ocMin: + case ocProduct: case ocSum: case ocExternal: @@ -1213,11 +1216,25 @@ void FormulaMissingContext::AddMoreArgs( FormulaTokenArray *pNewArr, const Missi } break; + case ocCount: + if (mnCurArg == 0 && mbEmpty) + { + // Excel expects at least one parameter in COUNT function + pNewArr->AddString(svl::SharedString::getEmptyString()); + } + break; + + case ocAverage: + if (mnCurArg == 0 && mbEmpty) + pNewArr->AddError(FormulaError::DivisionByZero); + break; + + case ocProduct: case ocSum: if ( mnCurArg == 0 && mbEmpty ) { - // Excel needs at least one parameter in SUM function - pNewArr->AddDouble( 0.0 ); // SUM() = 0 + // Excel needs at least one parameter in aggregate functions + pNewArr->AddDouble( 0.0 ); } break; diff --git a/sc/qa/unit/data/ods/tdf170565_empty_functions.ods b/sc/qa/unit/data/ods/tdf170565_empty_functions.ods index 2297a76f9e62..d909554f4cba 100644 Binary files a/sc/qa/unit/data/ods/tdf170565_empty_functions.ods and b/sc/qa/unit/data/ods/tdf170565_empty_functions.ods differ diff --git a/sc/qa/unit/subsequent_export_test5.cxx b/sc/qa/unit/subsequent_export_test5.cxx index 296ce5150f41..983b50782898 100644 --- a/sc/qa/unit/subsequent_export_test5.cxx +++ b/sc/qa/unit/subsequent_export_test5.cxx @@ -1435,6 +1435,9 @@ CPPUNIT_TEST_FIXTURE(ScExportTest5, testTdf170565_empty_functions) assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[1]/x:c[1]/x:f", u"SUM(0)"); assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[2]/x:c[1]/x:f", u"MIN(#VALUE!)"); assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[3]/x:c[1]/x:f", u"MAX(#VALUE!)"); + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[4]/x:c[1]/x:f", u"AVERAGE(#DIV/0!)"); + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[5]/x:c[1]/x:f", u"COUNT(\"\")"); + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[6]/x:c[1]/x:f", u"PRODUCT(0)"); // Further checks to ensure there are no regressions assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[1]/x:c[2]/x:f", u"SUM(,)"); assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[1]/x:c[3]/x:f", u"SUM(100)"); @@ -1445,6 +1448,9 @@ CPPUNIT_TEST_FIXTURE(ScExportTest5, testTdf170565_empty_functions) assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[3]/x:c[2]/x:f", u"MAX(,)"); assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[3]/x:c[3]/x:f", u"MAX(-100)"); assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[3]/x:c[4]/x:f", u"MAX(C1:C3)"); + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[4]/x:c[2]/x:f", u"AVERAGE(,)"); + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[5]/x:c[2]/x:f", u"COUNT(,)"); + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[6]/x:c[2]/x:f", u"PRODUCT(,)"); } CPPUNIT_PLUGIN_IMPLEMENT();
