]> source.dussan.org Git - poi.git/commitdiff
Fix bug #51115 - Handle DataFormatter escaping of "." in the same way as "-" and "/"
authorNick Burch <nick@apache.org>
Tue, 3 May 2011 05:42:41 +0000 (05:42 +0000)
committerNick Burch <nick@apache.org>
Tue, 3 May 2011 05:42:41 +0000 (05:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1098917 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/ss/usermodel/DataFormatter.java
src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java

index f10d4d36eb62bf63b4cdcfb97ea60718c55c1fbd..6280db36ad7db80f82b28e1c8762e58634f57568 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta3" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51115 - Handle DataFormatter escaping of "." in the same way as "-" and "/"</action>
            <action dev="poi-developers" type="fix">51100 - Fix IOUtils issue for NPOIFS reading from an InputStream where every block is full</action>
            <action dev="poi-developers" type="fix">50956 - Correct XSSF cell style cloning between workbooks</action>
            <action dev="poi-developers" type="add">Add get/setForceFormulaRecalculation for XSSF, and promote the methods to the common usermodel Sheet</action>
index 6c9412383d4c64f932354fd319b115cfef5ad1e1..9ae8b6bb5f86b0dcbb800e941d62ad0d8e49c32e 100644 (file)
@@ -347,6 +347,7 @@ public class DataFormatter {
         String formatStr = pFormatStr;
         formatStr = formatStr.replaceAll("\\\\-","-");
         formatStr = formatStr.replaceAll("\\\\,",",");
+        formatStr = formatStr.replaceAll("\\\\\\.","."); // . is a special regexp char
         formatStr = formatStr.replaceAll("\\\\ "," ");
         formatStr = formatStr.replaceAll("\\\\/","/"); // weird: m\\/d\\/yyyy 
         formatStr = formatStr.replaceAll(";@", "");
index 41c220c5d32aef1bc4fd3708a49248dc9c12ff53..2b505ac8b8d5ac4a5568e12374675291ce7102f7 100644 (file)
@@ -345,6 +345,18 @@ public class TestDataFormatter extends TestCase {
                 df2.formatRawCellContents(-1, -1, "mm/dd/yyyy"));
     }
 
+    public void testEscapes() {
+       DataFormatter dfUS = new DataFormatter(Locale.US);
+
+       assertEquals("1901-01-01", dfUS.formatRawCellContents(367.0, -1, "yyyy-mm-dd"));
+       assertEquals("1901-01-01", dfUS.formatRawCellContents(367.0, -1, "yyyy\\-mm\\-dd"));
+       
+       assertEquals("1901.01.01", dfUS.formatRawCellContents(367.0, -1, "yyyy.mm.dd"));
+       assertEquals("1901.01.01", dfUS.formatRawCellContents(367.0, -1, "yyyy\\.mm\\.dd"));
+       
+       assertEquals("1901/01/01", dfUS.formatRawCellContents(367.0, -1, "yyyy/mm/dd"));
+       assertEquals("1901/01/01", dfUS.formatRawCellContents(367.0, -1, "yyyy\\/mm\\/dd"));
+    }
 
     public void testOther() {
         DataFormatter dfUS = new DataFormatter(Locale.US, true);