<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>
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
formatStr = nFormatStr;
colourM = colorPattern.matcher(formatStr);
}
-
+
// try to extract special characters like currency
Matcher m = specialPatternGroup.matcher(formatStr);
while(m.find()) {
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