Author: gwoolsey
Date: Wed Apr 19 20:04:46 2017
New Revision: 1791964
URL: http://svn.apache.org/viewvc?rev=1791964&view=rev
Log:
Fix bug #61007
Revert to previous "expected" test results even though they don't match excel
for a specific case, to accommodate tighter logic about which format patterns
to send to CellFormat vs. handle directly in DataFormatter.
Send what was checked previously plus only multi-segment conditional range
formats. Allows existing tests to pass plus the new test with the case for
these conditional formats.
Modified:
poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java?rev=1791964&r1=1791963&r2=1791964&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Wed Apr
19 20:04:46 2017
@@ -128,6 +128,9 @@ public class DataFormatter implements Ob
/** Pattern to find "AM/PM" marker */
private static final Pattern amPmPattern =
Pattern.compile("((A|P)[M/P]*)", Pattern.CASE_INSENSITIVE);
+
+ /** Pattern to find formats with condition ranges e.g. [>=100] */
+ private static final Pattern rangeConditionalPattern =
Pattern.compile(".*\\[\\s*(>|>=|<|<=|=)\\s*[0-9]*\\.*[0-9].*");
/**
* A regex to find locale patterns like [$$-1009] and [$?-452].
@@ -318,7 +321,10 @@ public class DataFormatter implements Ob
// handle these ourselves in a special way.
// For now, if we detect 2+ parts, we call out to CellFormat to handle
it
// TODO Going forward, we should really merge the logic between the
two classes
- if (formatStr.contains(";") ) {
+ if (formatStr.contains(";") &&
+ (formatStr.indexOf(';') != formatStr.lastIndexOf(';')
+ || rangeConditionalPattern.matcher(formatStr).matches()
+ ) ) {
try {
// Ask CellFormat to get a formatter for it
CellFormat cfmt = CellFormat.getInstance(formatStr);
Modified:
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java?rev=1791964&r1=1791963&r2=1791964&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
Wed Apr 19 20:04:46 2017
@@ -318,7 +318,7 @@ public class TestDataFormatter {
//assertEquals("123", dfUS.formatRawCellContents(-123.321, -1, "0
?/?;0"));
//Bug54868 patch has a hit on the first string before the ";"
- assertEquals("123", dfUS.formatRawCellContents(-123.321, -1, "0
?/?;0"));
+ assertEquals("-123 1/3", dfUS.formatRawCellContents(-123.321, -1, "0
?/?;0"));
assertEquals("123 1/3", dfUS.formatRawCellContents(123.321, -1, "0
?/?;0"));
//Bug53150 formatting a whole number with fractions should just give
the number
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]