sc/inc/scmatrix.hxx | 2 +- sc/source/core/tool/interpr1.cxx | 20 ++++++++++++++++++++ sc/source/core/tool/scmatrix.cxx | 30 +++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 8 deletions(-)
New commits: commit 7def66a03ba888762c4902fcc64c41b45a6fd41a Author: Eike Rathke <er...@redhat.com> AuthorDate: Thu Aug 20 17:32:25 2020 +0200 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Sat Aug 22 15:37:04 2020 +0200 Resolves: tdf#132105 COUNTBLANK() handle external references and array/matrix This is a combination of 2 commits. Resolves: tdf#132105 COUNTBLANK() handle external references and array/matrix Change-Id: I6f39c67a20c0d683da9f14775ce8cbddf2f92349 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101079 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit 70126c3eb7a532b5f1e852d9ac81d0ece6edf0c3) Conflicts: sc/source/core/tool/interpr1.cxx Change-Id: I17a317b9dd883900bc8b434d51e8d72e082af0f7 Follow-up: tdf#132105 COUNTBLANK() count empty strings also in array/matrix For Excel interoperability this somewhat is a *visual* blank, unlike ISBLANK() empty strings are counted as blanks. An empty string in a matrix can be either a formula result transformed to matrix, or literal input in an inline array. There's no way to differentiate the origin. Change-Id: Ib799e95517d95e1a7c28fc4335bd0040f3629ad1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101083 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit 64e19525eebd0974f1609300d95a74c1e083e8e3) Conflicts: sc/source/core/tool/interpr1.cxx Change-Id: I9f78c0011f9edd116d7ba80e31bd8303c87271aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101086 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index 2efa73c4a975..e9a71e82b94d 100644 --- a/sc/inc/scmatrix.hxx +++ b/sc/inc/scmatrix.hxx @@ -365,7 +365,7 @@ public: IterateResult Sum( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ; IterateResult SumSquare( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ; IterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ; - size_t Count(bool bCountStrings, bool bCountErrors) const ; + size_t Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings = false) const ; size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const ; size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const ; diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 8af767c9b00e..4de760cedd0d 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -5170,6 +5170,26 @@ void ScInterpreter::ScCountEmptyCells() } } break; + case svMatrix: + case svExternalSingleRef: + case svExternalDoubleRef: + { + ScMatrixRef xMat = GetMatrix(); + if (!xMat) + SetError( FormulaError::IllegalParameter); + else + { + SCSIZE nC, nR; + xMat->GetDimensions( nC, nR); + nMaxCount = nC * nR; + // Numbers (implicit), strings and error values, ignore empty + // strings as those if not entered in an inline array are the + // result of a formula, to be par with a reference to formula + // cell as *visual* blank, see isCellContentEmpty() above. + nCount = xMat->Count( true, true, true); + } + } + break; default : SetError(FormulaError::IllegalParameter); break; } if (xResMat) diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index fdba2f1b7989..d23c3b698537 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -311,7 +311,7 @@ public: ScMatrix::IterateResult Sum( bool bTextAsZero, bool bIgnoreErrorValues ) const; ScMatrix::IterateResult SumSquare( bool bTextAsZero, bool bIgnoreErrorValues ) const; ScMatrix::IterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues ) const; - size_t Count(bool bCountStrings, bool bCountErrors) const; + size_t Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings) const; size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const; size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const; @@ -1297,9 +1297,11 @@ class CountElements size_t mnCount; bool mbCountString; bool mbCountErrors; + bool mbIgnoreEmptyStrings; public: - explicit CountElements(bool bCountString, bool bCountErrors) : - mnCount(0), mbCountString(bCountString), mbCountErrors(bCountErrors) {} + explicit CountElements(bool bCountString, bool bCountErrors, bool bIgnoreEmptyStrings) : + mnCount(0), mbCountString(bCountString), mbCountErrors(bCountErrors), + mbIgnoreEmptyStrings(bIgnoreEmptyStrings) {} size_t getCount() const { return mnCount; } @@ -1327,7 +1329,21 @@ public: break; case mdds::mtm::element_string: if (mbCountString) + { mnCount += node.size; + if (mbIgnoreEmptyStrings) + { + typedef MatrixImplType::string_block_type block_type; + + block_type::const_iterator it = block_type::begin(*node.data); + block_type::const_iterator itEnd = block_type::end(*node.data); + for (; it != itEnd; ++it) + { + if (it->isEmpty()) + --mnCount; + } + } + } break; case mdds::mtm::element_empty: default: @@ -2117,9 +2133,9 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero, bool bIgnoreErro return GetValueWithCount<sc::op::Product>(bTextAsZero, bIgnoreErrorValues, maMat); } -size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors) const +size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings) const { - CountElements aFunc(bCountStrings, bCountErrors); + CountElements aFunc(bCountStrings, bCountErrors, bIgnoreEmptyStrings); aFunc = maMat.walk(aFunc); return aFunc.getCount(); } @@ -3233,9 +3249,9 @@ ScMatrix::IterateResult ScMatrix::Product(bool bTextAsZero, bool bIgnoreErrorVal return pImpl->Product(bTextAsZero, bIgnoreErrorValues); } -size_t ScMatrix::Count(bool bCountStrings, bool bCountErrors) const +size_t ScMatrix::Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings) const { - return pImpl->Count(bCountStrings, bCountErrors); + return pImpl->Count(bCountStrings, bCountErrors, bIgnoreEmptyStrings); } size_t ScMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits