Author: gwoolsey
Date: Wed Apr 19 18:10:52 2017
New Revision: 1791949
URL: http://svn.apache.org/viewvc?rev=1791949&view=rev
Log:
Fix bug #61007
use CellFormat for all format strings containing multiple parts (";" delimited)
and update unit test to expect the same values as Excel. Also added tests for
the failing 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=1791949&r1=1791948&r2=1791949&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 18:10:52 2017
@@ -312,14 +312,13 @@ public class DataFormatter implements Ob
String formatStr = formatStrIn;
- // Excel supports 3+ part conditional data formats, eg
positive/negative/zero,
+ // Excel supports 2+ part conditional data formats, eg
positive/negative/zero,
// or (>1000),(>0),(0),(negative). As Java doesn't handle these kinds
// of different formats for different ranges, just +ve/-ve, we need
to
// handle these ourselves in a special way.
- // For now, if we detect 3+ parts, we call out to CellFormat to handle
it
+ // 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(";") &&
- formatStr.indexOf(';') != formatStr.lastIndexOf(';')) {
+ if (formatStr.contains(";") ) {
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=1791949&r1=1791948&r2=1791949&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 18:10:52 2017
@@ -198,6 +198,15 @@ public class TestDataFormatter {
);
}
}
+
+ @Test
+ public void testConditionalRanges() {
+ DataFormatter dfUS = new DataFormatter(Locale.US);
+
+ String format = "[>=10]#,##0;[<10]0.0";
+ assertEquals("Wrong format for " + format, "17,876",
dfUS.formatRawCellContents(17876.000, -1, format));
+ assertEquals("Wrong format for " + format, "9.7",
dfUS.formatRawCellContents(9.71, -1, format));
+ }
/**
* Test how we handle negative and zeros.
@@ -309,7 +318,8 @@ 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 1/3", dfUS.formatRawCellContents(-123.321, -1, "0
?/?;0"));
+ assertEquals("123", 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
assertEquals("1", dfUS.formatRawCellContents(1.0, -1, "# #/#"));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]