formula/source/core/api/token.cxx | 21 +++++++++++++++++++-- sc/qa/unit/data/ods/tdf170565_empty_functions.ods |binary sc/qa/unit/subsequent_export_test4.cxx | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-)
New commits: commit 8855ba150b5783ae0ac36063e5ceb4baa5350676 Author: Karthik Godha <[email protected]> AuthorDate: Fri Feb 13 18:02:30 2026 +0530 Commit: Aron Budea <[email protected]> CommitDate: Mon Feb 16 12:06:28 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]> diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index e7689e1d1407..51521a716183 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_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index be11baa83253..5af9933e5a5d 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -2452,6 +2452,9 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 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)"); @@ -2462,6 +2465,9 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 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();
