From 6576890e534dda21ac1167aa1ecefc2df72a6fc5 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 3 May 2011 05:42:41 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/ss/usermodel/DataFormatter.java | 1 + .../apache/poi/ss/usermodel/TestDataFormatter.java | 12 ++++++++++++ 3 files changed, 14 insertions(+) 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 @@ + 51115 - Handle DataFormatter escaping of "." in the same way as "-" and "/" 51100 - Fix IOUtils issue for NPOIFS reading from an InputStream where every block is full 50956 - Correct XSSF cell style cloning between workbooks Add get/setForceFormulaRecalculation for XSSF, and promote the methods to the common usermodel Sheet 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); -- 2.39.5