From e4b3772ef966fb3db8dfaa55dfc5f5582d61761d Mon Sep 17 00:00:00 2001 From: Winfried Donkers Date: Fri, 8 Jul 2016 09:46:10 +0200 Subject: tdf#100762 Add support for array arguments to NPV. Change-Id: I8935ed85df456bd5f86adf0392a19eb0b6a2f656 Reviewed-on: https://gerrit.libreoffice.org/27034 Tested-by: Jenkins Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- sc/source/core/tool/interpr2.cxx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'sc') diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 8418062b8606..458236ebca7e 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -1316,6 +1316,41 @@ void ScInterpreter::ScNPV() SetError(nErr); } break; + case svMatrix : + case svExternalSingleRef: + case svExternalDoubleRef: + { + ScMatrixRef pMat = GetMatrix(); + if (pMat) + { + SCSIZE nC, nR; + pMat->GetDimensions(nC, nR); + if (nC == 0 || nR == 0) + { + PushIllegalArgument(); + return; + } + else + { + double fx; + for ( SCSIZE j = 0; j < nC; j++ ) + { + for (SCSIZE k = 0; k < nR; ++k) + { + if (!pMat->IsValue(j,k)) + { + PushIllegalArgument(); + return; + } + fx = pMat->GetDouble(j,k); + nVal += (fx / pow(1.0 + nInterest, nCount)); + nCount++; + } + } + } + } + } + break; default : SetError(errIllegalParameter); break; } } -- cgit