From d0f2a79c0723720f9c986a2061080b686264df83 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Mon, 2 Feb 2009 19:42:57 +0000 Subject: Fix for bug 46647 - COUNTIF NE operator and other special cases involving type conversion git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740088 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/formula/functions/Countif.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/java') diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java b/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java index db973ec21b..babedab61d 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Countif.java @@ -128,7 +128,7 @@ public final class Countif implements Function { case NONE: case EQ: return cmpResult == 0; - case NE: return cmpResult == 0; + case NE: return cmpResult != 0; case LT: return cmpResult < 0; case LE: return cmpResult <= 0; case GT: return cmpResult > 0; @@ -160,14 +160,27 @@ public final class Countif implements Function { double testValue; if(x instanceof StringEval) { // if the target(x) is a string, but parses as a number - // it may still count as a match + // it may still count as a match, only for the equality operator + switch (_operator.getCode()) { + case CmpOp.EQ: + case CmpOp.NONE: + break; + case CmpOp.NE: + // Always matches (inconsistent with above two cases). + // for example '<>123' matches '123', '4', 'abc', etc + return true; + default: + // never matches (also inconsistent with above three cases). + // for example '>5' does not match '6', + return false; + } StringEval se = (StringEval)x; Double val = OperandResolver.parseDouble(se.getStringValue()); if(val == null) { // x is text that is not a number return false; } - testValue = val.doubleValue(); + return _value == val.doubleValue(); } else if((x instanceof NumberEval)) { NumberEval ne = (NumberEval) x; testValue = ne.getNumberValue(); @@ -249,6 +262,7 @@ public final class Countif implements Function { _pattern = getWildCardPattern(value); break; default: + // pattern matching is never used for < > <= => _pattern = null; } } -- cgit v1.2.3