diff options
-rw-r--r-- | sc/inc/scmatrix.hxx | 6 | ||||
-rw-r--r-- | sc/source/core/tool/interpr6.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 32 |
3 files changed, 29 insertions, 13 deletions
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index e177bedade91..64147c2c3716 100644 --- a/sc/inc/scmatrix.hxx +++ b/sc/inc/scmatrix.hxx @@ -366,7 +366,7 @@ public: virtual IterateResult Sum(bool bTextAsZero) const = 0; virtual IterateResult SumSquare(bool bTextAsZero) const = 0; virtual IterateResult Product(bool bTextAsZero) const = 0; - virtual size_t Count(bool bCountStrings) const = 0; + virtual size_t Count(bool bCountStrings, bool bCountErrors) const = 0; virtual size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const = 0; virtual size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const = 0; @@ -574,7 +574,7 @@ public: virtual IterateResult Sum(bool bTextAsZero) const override; virtual IterateResult SumSquare(bool bTextAsZero) const override; virtual IterateResult Product(bool bTextAsZero) const override; - virtual size_t Count(bool bCountStrings) const override; + virtual size_t Count(bool bCountStrings, bool bCountErrors) const override; virtual size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const override; virtual size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const override; @@ -785,7 +785,7 @@ public: virtual IterateResult Sum(bool bTextAsZero) const override; virtual IterateResult SumSquare(bool bTextAsZero) const override; virtual IterateResult Product(bool bTextAsZero) const override; - virtual size_t Count(bool bCountStrings) const override; + virtual size_t Count(bool bCountStrings, bool bCountErrors) const override; virtual size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const override; virtual size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const override; diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx index 306d81fef1dc..78d6f47c2589 100644 --- a/sc/source/core/tool/interpr6.cxx +++ b/sc/source/core/tool/interpr6.cxx @@ -433,10 +433,10 @@ void IterateMatrix( } break; case ifCOUNT: - rCount += pMat->Count(bTextAsZero); + rCount += pMat->Count(bTextAsZero, false); // do not count error values break; case ifCOUNT2: - rCount += pMat->Count(true); + rCount += pMat->Count(true, true); // do count error values break; case ifPRODUCT: { diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index 279701e98cbf..1a5d0121389f 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -284,7 +284,7 @@ public: ScMatrix::IterateResult Sum(bool bTextAsZero) const; ScMatrix::IterateResult SumSquare(bool bTextAsZero) const; ScMatrix::IterateResult Product(bool bTextAsZero) const; - size_t Count(bool bCountStrings) const; + size_t Count(bool bCountStrings, bool bCountErrors) 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; @@ -1163,8 +1163,10 @@ class CountElements : public std::unary_function<MatrixImplType::element_block_n { size_t mnCount; bool mbCountString; + bool mbCountErrors; public: - explicit CountElements(bool bCountString) : mnCount(0), mbCountString(bCountString) {} + explicit CountElements(bool bCountString, bool bCountErrors) : + mnCount(0), mbCountString(bCountString), mbCountErrors(bCountErrors) {} size_t getCount() const { return mnCount; } @@ -1173,6 +1175,20 @@ public: switch (node.type) { case mdds::mtm::element_numeric: + mnCount += node.size; + if (!mbCountErrors) + { + typedef MatrixImplType::numeric_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 (!::rtl::math::isFinite(*it)) + --mnCount; + } + } + break; case mdds::mtm::element_boolean: mnCount += node.size; break; @@ -1782,9 +1798,9 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero) const return GetValueWithCount<sc::op::Product>(bTextAsZero, maMat); } -size_t ScMatrixImpl::Count(bool bCountStrings) const +size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors) const { - CountElements aFunc(bCountStrings); + CountElements aFunc(bCountStrings, bCountErrors); maMat.walk(aFunc); return aFunc.getCount(); } @@ -2682,9 +2698,9 @@ ScMatrix::IterateResult ScFullMatrix::Product(bool bTextAsZero) const return pImpl->Product(bTextAsZero); } -size_t ScFullMatrix::Count(bool bCountStrings) const +size_t ScFullMatrix::Count(bool bCountStrings, bool bCountErrors) const { - return pImpl->Count(bCountStrings); + return pImpl->Count(bCountStrings, bCountErrors); } size_t ScFullMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const @@ -3581,10 +3597,10 @@ ScMatrix::IterateResult ScVectorRefMatrix::Product(bool bTextAsZero) const return mpFullMatrix->Product(bTextAsZero); } -size_t ScVectorRefMatrix::Count(bool bCountStrings) const +size_t ScVectorRefMatrix::Count(bool bCountStrings, bool bCountErrors) const { const_cast<ScVectorRefMatrix*>(this)->ensureFullMatrix(); - return mpFullMatrix->Count(bCountStrings); + return mpFullMatrix->Count(bCountStrings, bCountErrors); } size_t ScVectorRefMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const |