Browse Source

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
tags/REL_3_8_BETA3
Nick Burch 13 years ago
parent
commit
6576890e53

+ 1
- 0
src/documentation/content/xdocs/status.xml View 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>

+ 1
- 0
src/java/org/apache/poi/ss/usermodel/DataFormatter.java View 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(";@", "");

+ 12
- 0
src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java View 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);

Loading…
Cancel
Save