mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[bug-63211] fix issue with escaped % in custom number format
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
82a33995ce
commit
b9d1e9c27f
@ -313,7 +313,8 @@ public class DataFormatter {
|
||||
// int i = cellValue > 0.0 ? 0 : cellValue < 0.0 ? 1 : 2;
|
||||
// String formatStr = (i < formatBits.length) ? formatBits[i] : formatBits[0];
|
||||
|
||||
String formatStr = formatStrIn;
|
||||
// this replace is done to fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63211
|
||||
String formatStr = formatStrIn.replace("\\%", "\'%\'");
|
||||
|
||||
// Excel supports 2+ part conditional data formats, eg positive/negative/zero,
|
||||
// or (>1000),(>0),(0),(negative). As Java doesn't handle these kinds
|
||||
|
||||
@ -1020,6 +1020,18 @@ class TestDataFormatter {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug63211() {
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
// https://bz.apache.org/bugzilla/show_bug.cgi?id=63211
|
||||
// this format is an escaped % so is not the built-in percent which treats 0.125 as 12.5%
|
||||
// this escaped format just appends a % to the raw decimal - so 12.5 becomes 12.5%
|
||||
assertEquals("12.5%",
|
||||
formatter.formatRawCellContents(12.5, -1, "0.0\\%;\\-0.0\\%"));
|
||||
assertEquals("-12.5%",
|
||||
formatter.formatRawCellContents(-12.5, -1, "0.0\\%;\\-0.0\\%"));
|
||||
}
|
||||
|
||||
private void doFormatTestSequential(DataFormatter formatter) {
|
||||
for (int i = 0; i < 1_000; i++) {
|
||||
assertTrue(doFormatTest(formatter, 43551.50990171296, "3/27/19 12:14:15 PM", i));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user