poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r954416 - 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 Mon, 14 Jun 2010 11:45:09 GMT
Author: nick
Date: Mon Jun 14 11:45:09 2010
New Revision: 954416

URL: http://svn.apache.org/viewvc?rev=954416&view=rev
Log:
When formatting numbers with DataFormatter, handle brackets following colours

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=954416&r1=954415&r2=954416&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Jun 14 11:45:09 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta2" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">When formatting numbers with DataFormatter,
handle brackets following colours</action>
         </release>
         <release version="3.7-beta1" date="2010-06-16">
            <action dev="POI-DEVELOPERS" type="add">48574 - further XWPF support for
tables, paragraphs, including enhanced support for adding new ones</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=954416&r1=954415&r2=954416&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 Mon Jun 14 11:45:09
2010
@@ -233,14 +233,14 @@ public class DataFormatter {
            int at = formatStr.indexOf(colour);
            if(at == -1) break;
            String nFormatStr = formatStr.substring(0,at) +
-              formatStr.substring(at+colour.length()+1);
+              formatStr.substring(at+colour.length());
            if(nFormatStr.equals(formatStr)) break;
 
            // Try again in case there's multiple
            formatStr = nFormatStr;
            colourM = colorPattern.matcher(formatStr);
         }
-        
+
         // try to extract special characters like currency
         Matcher m = specialPatternGroup.matcher(formatStr);
         while(m.find()) {

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=954416&r1=954415&r2=954416&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 Mon Jun 14
11:45:09 2010
@@ -77,6 +77,44 @@ public class TestDataFormatter extends T
        assertEquals("[ab]12.34[x]", dfUS.formatRawCellContents(12.343, -1, "[ab]##.##[x]"));
     }
     
+    public void testColoursAndBrackets() {
+       DataFormatter dfUS = new DataFormatter(Locale.US);
+       
+       // Without currency symbols
+       String[] formats = new String[] {
+             "#,##0.00;[Blue](#,##0.00)",
+       };
+       for(String format : formats) {
+          assertEquals(
+                "Wrong format for: " + format,
+                "12.34",
+                dfUS.formatRawCellContents(12.343, -1, format)
+          );
+          assertEquals(
+                "Wrong format for: " + format,
+                "(12.34)",
+                dfUS.formatRawCellContents(-12.343, -1, format)
+          );
+       }
+       
+       // With
+       formats = new String[] {
+             "$#,##0.00;[Red]($#,##0.00)"
+       };
+       for(String format : formats) {
+          assertEquals(
+                "Wrong format for: " + format,
+                "$12.34",
+                dfUS.formatRawCellContents(12.343, -1, format)
+          );
+          assertEquals(
+                "Wrong format for: " + format,
+                "($12.34)",
+                dfUS.formatRawCellContents(-12.343, -1, format)
+          );
+       }
+    }
+    
     /**
      * Test how we handle negative and zeros.
      * Note - some tests are disabled as DecimalFormat



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


Mime
View raw message