Browse Source

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.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791964 13f79535-47bb-0310-9956-ffa450edef68
pull/53/head
Greg Woolsey 7 years ago
parent
commit
6e0a5916b5

+ 7
- 1
src/java/org/apache/poi/ss/usermodel/DataFormatter.java View File

@@ -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);

+ 1
- 1
src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java View File

@@ -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

Loading…
Cancel
Save