You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2024/03/06 08:21:11 UTC

[Bug 68714] New: Operator BETWEEN should work both ways

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: jdcoffre@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-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 68714] Operator BETWEEN should work both ways

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68714

Matafagafo <ma...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matafagafo@gmail.com

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


[Bug 68714] Operator BETWEEN should work both ways

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68714

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #1 from Dominik Stadler <do...@gmx.at> ---
There is also a 2nd enum DataValidationEvaluator.OperatorEnum which might need
similar adjustment. 

A test-case which verifies the fix would be good so we ensure it is staying
this way in the future.

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