diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java index f8b09970e..4f4fae988 100644 --- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -128,6 +128,9 @@ public class DataFormatter implements Observer { /** 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 Observer { // 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); diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java index a703b80f2..b4f3b7dde 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -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