mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Bug 65190: Handle decimal format '0#' the same way as Excel
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923056 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
534d24dc74
commit
a4097e05aa
@ -162,6 +162,11 @@ public class DataFormatter {
|
||||
*/
|
||||
private static final Pattern alternateGrouping = Pattern.compile("([#0]([^.#0])[#0]{3})");
|
||||
|
||||
/**
|
||||
* For handling '0#' properly
|
||||
*/
|
||||
private static final Pattern decimalFormatFix = Pattern.compile("0+#");
|
||||
|
||||
/**
|
||||
* Cells formatted with a date or time format and which contain invalid date or time values
|
||||
* show 255 pound signs ("#").
|
||||
@ -850,6 +855,11 @@ public class DataFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
// Excel ignores leading zeros, but Java fails with an exception below
|
||||
if (decimalFormatFix.matcher(format).matches()) {
|
||||
format = "#";
|
||||
}
|
||||
|
||||
try {
|
||||
return new InternalDecimalFormatWithScale(format, symbols);
|
||||
} catch(IllegalArgumentException iae) {
|
||||
|
||||
@ -1207,4 +1207,27 @@ class TestDataFormatter {
|
||||
assertEquals("25571.751069247686", df.formatCellValue(cell));*/
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug65190() {
|
||||
DataFormatter formatter = new DataFormatter(Locale.ENGLISH);
|
||||
|
||||
assertEquals("12334567890",
|
||||
formatter.formatRawCellContents(12334567890.0, 0, "0"));
|
||||
assertEquals("12334567890",
|
||||
formatter.formatRawCellContents(12334567890.0, 0, "#"));
|
||||
assertEquals("12334567890",
|
||||
formatter.formatRawCellContents(12334567890.0, 0, "#0"));
|
||||
assertEquals("12334567890",
|
||||
formatter.formatRawCellContents(12334567890.0, 0, "0#"));
|
||||
|
||||
assertEquals("12334567890123",
|
||||
formatter.formatRawCellContents(12334567890123.0, 0, "0"));
|
||||
assertEquals("12334567890123",
|
||||
formatter.formatRawCellContents(12334567890123.0, 0, "#"));
|
||||
assertEquals("12334567890123",
|
||||
formatter.formatRawCellContents(12334567890123.0, 0, "#0"));
|
||||
assertEquals("12334567890123",
|
||||
formatter.formatRawCellContents(12334567890123.0, 0, "0#"));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user