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
This commit is contained in:
Nick Burch 2011-05-03 05:42:41 +00:00
parent 1473cef845
commit ffcd5beed5
3 changed files with 14 additions and 0 deletions

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>

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(";@", "");

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);