summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-05-23 10:39:25 +0200
committerEike Rathke <erack@redhat.com>2017-05-23 10:41:08 +0200
commit6a6aa56b45f19c250e9c4111b478203ddb75478b (patch)
treeff8311404500f36b21ac8c9aad6706b3d291a561
parent44a1f0c17d3c5b212ff60b2f24f50693b3da9eab (diff)
Handle SUMIF and AVERAGEIF with array of references, tdf#58874
Change-Id: I37bad7b85ee61631399f1b49d0bc9be3b8d00423
-rw-r--r--sc/source/core/tool/interpr1.cxx32
1 files changed, 26 insertions, 6 deletions
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 51ddade6e1e8..e5ba5ede6b0c 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -5115,6 +5115,10 @@ void ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
double fCount = 0.0;
bool bNull = true;
short nParam = 1;
+ const SCSIZE nMatRows = GetRefListArrayMaxSize( nParam);
+ // There's either one RefList and nothing else, or none.
+ ScMatrixRef xResMat = (nMatRows ? GetNewMat( 1, nMatRows) : nullptr);
+ SCSIZE nRefListArrayPos = 0;
size_t nRefInList = 0;
while (nParam-- > 0)
{
@@ -5130,10 +5134,12 @@ void ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
case svRefList :
if (bSumExtraRange)
{
+ /* TODO: this could resolve if all refs are of the same size */
SetError( FormulaError::IllegalParameter);
}
else
{
+ nRefListArrayPos = nRefInList;
ScRange aRange;
PopDoubleRef( aRange, nParam, nRefInList);
aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
@@ -5370,14 +5376,28 @@ void ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
PushError( FormulaError::IllegalParameter);
return;
}
- }
- switch( eFunc )
- {
- case ifSUMIF: fRes = ::rtl::math::approxAdd( fSum, fMem ); break;
- case ifAVERAGEIF: fRes = div( ::rtl::math::approxAdd( fSum, fMem ), fCount); break;
+ switch( eFunc )
+ {
+ case ifSUMIF: fRes = ::rtl::math::approxAdd( fSum, fMem ); break;
+ case ifAVERAGEIF: fRes = div( ::rtl::math::approxAdd( fSum, fMem ), fCount); break;
+ }
+ if (xResMat)
+ {
+ if (nGlobalError == FormulaError::NONE)
+ xResMat->PutDouble( fRes, 0, nRefListArrayPos);
+ else
+ {
+ xResMat->PutError( nGlobalError, 0, nRefListArrayPos);
+ nGlobalError = FormulaError::NONE;
+ }
+ fRes = fSum = fMem = fCount = 0.0;
+ }
}
- PushDouble( fRes);
+ if (xResMat)
+ PushMatrix( xResMat);
+ else
+ PushDouble( fRes);
}
void ScInterpreter::ScSumIf()