aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-05-03 05:42:41 +0000
committerNick Burch <nick@apache.org>2011-05-03 05:42:41 +0000
commit6576890e534dda21ac1167aa1ecefc2df72a6fc5 (patch)
tree05f758891ed2d3e7373657e411423f65f02be69e
parent692bab9b9ee10e507e930f92b440351bf7c409bc (diff)
downloadpoi-6576890e534dda21ac1167aa1ecefc2df72a6fc5.tar.gz
poi-6576890e534dda21ac1167aa1ecefc2df72a6fc5.zip
Fix bug #51115 - Handle DataFormatter escaping of "." in the same way as "-" and "/"
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1098917 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/ss/usermodel/DataFormatter.java1
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java12
3 files changed, 14 insertions, 0 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index f10d4d36eb..6280db36ad 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -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>
diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
index 6c9412383d..9ae8b6bb5f 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -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(";@", "");
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index 41c220c5d3..2b505ac8b8 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -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);