mirror of https://github.com/apache/poi.git
When formatting numbers with DataFormatter, handle brackets following colours
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@954416 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9c6fdb6f53
commit
36c5190f57
|
@ -34,6 +34,7 @@
|
|||
|
||||
<changes>
|
||||
<release version="3.7-beta2" date="2010-??-??">
|
||||
<action dev="POI-DEVELOPERS" type="fix">When formatting numbers with DataFormatter, handle brackets following colours</action>
|
||||
</release>
|
||||
<release version="3.7-beta1" date="2010-06-16">
|
||||
<action dev="POI-DEVELOPERS" type="add">48574 - further XWPF support for tables, paragraphs, including enhanced support for adding new ones</action>
|
||||
|
|
|
@ -233,7 +233,7 @@ public class DataFormatter {
|
|||
int at = formatStr.indexOf(colour);
|
||||
if(at == -1) break;
|
||||
String nFormatStr = formatStr.substring(0,at) +
|
||||
formatStr.substring(at+colour.length()+1);
|
||||
formatStr.substring(at+colour.length());
|
||||
if(nFormatStr.equals(formatStr)) break;
|
||||
|
||||
// Try again in case there's multiple
|
||||
|
|
|
@ -77,6 +77,44 @@ public class TestDataFormatter extends TestCase {
|
|||
assertEquals("[ab]12.34[x]", dfUS.formatRawCellContents(12.343, -1, "[ab]##.##[x]"));
|
||||
}
|
||||
|
||||
public void testColoursAndBrackets() {
|
||||
DataFormatter dfUS = new DataFormatter(Locale.US);
|
||||
|
||||
// Without currency symbols
|
||||
String[] formats = new String[] {
|
||||
"#,##0.00;[Blue](#,##0.00)",
|
||||
};
|
||||
for(String format : formats) {
|
||||
assertEquals(
|
||||
"Wrong format for: " + format,
|
||||
"12.34",
|
||||
dfUS.formatRawCellContents(12.343, -1, format)
|
||||
);
|
||||
assertEquals(
|
||||
"Wrong format for: " + format,
|
||||
"(12.34)",
|
||||
dfUS.formatRawCellContents(-12.343, -1, format)
|
||||
);
|
||||
}
|
||||
|
||||
// With
|
||||
formats = new String[] {
|
||||
"$#,##0.00;[Red]($#,##0.00)"
|
||||
};
|
||||
for(String format : formats) {
|
||||
assertEquals(
|
||||
"Wrong format for: " + format,
|
||||
"$12.34",
|
||||
dfUS.formatRawCellContents(12.343, -1, format)
|
||||
);
|
||||
assertEquals(
|
||||
"Wrong format for: " + format,
|
||||
"($12.34)",
|
||||
dfUS.formatRawCellContents(-12.343, -1, format)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test how we handle negative and zeros.
|
||||
* Note - some tests are disabled as DecimalFormat
|
||||
|
|
Loading…
Reference in New Issue