poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1225093 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/ss/usermodel/DataFormatter.java testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
Date Wed, 28 Dec 2011 05:10:25 GMT
Author: nick
Date: Wed Dec 28 05:10:24 2011
New Revision: 1225093

URL: http://svn.apache.org/viewvc?rev=1225093&view=rev
Log:
Bug #52389 - Handle ?/? format fractions as well as #/# ones, and tighten the criteria for
triggering fraction formatting matching

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    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/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1225093&r1=1225092&r2=1225093&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Dec 28 05:10:24 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="add">52389 - Support ?/? as well as #/#
fractions, and tighten DataFormatter rules for fraction matching</action>
            <action dev="poi-developers" type="add">52200 - Updated XWPF table example
code </action>
            <action dev="poi-developers" type="add">52378 - Support for WORKDAY and
NETWORKDAYS functions</action>
            <action dev="poi-developers" type="add">52349 - Merge the logic between
the TEXT function and DataFormatter</action>

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=1225093&r1=1225092&r2=1225093&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 Dec 28 05:10:24
2011
@@ -349,8 +349,9 @@ public class DataFormatter {
         }
         
         // Excel supports fractions in format strings, which Java doesn't
-        if (formatStr.indexOf("/") == formatStr.lastIndexOf("/") && 
-              formatStr.indexOf("/") >= 0 && !formatStr.contains("-")) {
+        if (!formatStr.contains("-") &&
+              (formatStr.indexOf("#/#") >= 0 && formatStr.indexOf("#/#") == formatStr.lastIndexOf("#/#"))
||
+              (formatStr.indexOf("?/?") >= 0 && formatStr.indexOf("?/?") == formatStr.lastIndexOf("?/?")))
{
             return new FractionFormat(formatStr);
         }
         
@@ -985,6 +986,8 @@ public class DataFormatter {
           if (wholePart * decPart == 0) {
              return "0";
           }
+          
+          // Split the format string into decimal and fraction parts
           String[] parts = str.split(" ");
           String[] fractParts;
           if (parts.length == 2) {
@@ -992,6 +995,11 @@ public class DataFormatter {
           } else {
              fractParts = str.split("/");
           }
+          
+          // Excel supports both #/# and ?/?, but Java only the former
+          for (int i=0; i<fractParts.length; i++) {
+             fractParts[i] = fractParts[i].replace('?', '#');
+          }
 
           if (fractParts.length == 2) {
              double minVal = 1.0;

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=1225093&r1=1225092&r2=1225093&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 Dec 28
05:10:24 2011
@@ -168,9 +168,15 @@ public class TestDataFormatter extends T
     public void testFractions() {
        DataFormatter dfUS = new DataFormatter(Locale.US);
        
-       assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# #/#"));
+       // Excel often prefers "# #/#"
+       assertEquals("321 1/3",   dfUS.formatRawCellContents(321.321, -1, "# #/#"));
        assertEquals("321 26/81", dfUS.formatRawCellContents(321.321, -1, "# #/##"));
-       assertEquals("26027/81", dfUS.formatRawCellContents(321.321, -1, "#/##"));
+       assertEquals("26027/81",  dfUS.formatRawCellContents(321.321, -1, "#/##"));
+
+       // OOo seems to like the "# ?/?" form
+       assertEquals("321 1/3",   dfUS.formatRawCellContents(321.321, -1, "# ?/?"));
+       assertEquals("321 26/81", dfUS.formatRawCellContents(321.321, -1, "# ?/??"));
+       assertEquals("26027/81",  dfUS.formatRawCellContents(321.321, -1, "?/??"));
     }
     
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message