https://bz.apache.org/bugzilla/show_bug.cgi?id=68714

            Bug ID: 68714
           Summary: Operator BETWEEN should work both ways
           Product: POI
           Version: 5.2.3-FINAL
          Hardware: PC
                OS: Mac OS X 10.1
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SS Common
          Assignee: dev@poi.apache.org
          Reporter: jdcof...@gmail.com
  Target Milestone: ---

Created attachment 39610
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=39610&action=edit
Reproducer with conditional formatting rules

With Excel, the conditional formatting the rule "compare cell between 2 values"
will evaluate the formula both ways:
 - val1 < cell.value < val2
 - val2 < cell.value < val1

There is no assumption what is the lowest value and the highest one. 

With Apache POI, the evaluation is done one way which suppose that the lowest
value is the first one and the highest one is the second:
 - return cellValue.compareTo(v1) >= 0 && cellValue.compareTo(v2) <= 0;

https://github.com/apache/poi/blob/ae2f0945cd2ab37260e46ab46c54b8f68a131aea/poi/src/main/java/org/apache/poi/ss/formula/OperatorEnum.java#L92

As a consequence, each time the lowest value is passed as a second value, the
expression is always false.

Code should look like:
 return (cellValue.compareTo(v1) >= 0 && cellValue.compareTo(v2) <= 0 ) ||
                 ((cellValue.compareTo(v1) <= 0 && cellValue.compareTo(v2) >= 0
)) ;

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to