tdf#170565: Handle empty aggregate functions in XLSX

This is an extension of 3cbf4957d3,
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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Aron Budea <aron.budea@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200162
Tested-by: Jenkins
This commit is contained in:
Karthik Godha
2026-02-24 23:35:56 +01:00
committed by Aron Budea
parent 3531740e12
commit 8ea0c3678f
3 changed files with 25 additions and 2 deletions
+19 -2
View File
@@ -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;
Binary file not shown.
+6
View File
@@ -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();