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
5c68b8bd76
commit
5c3415e09c
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.7-beta2" date="2010-??-??">
|
<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>
|
||||||
<release version="3.7-beta1" date="2010-06-16">
|
<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>
|
<action dev="POI-DEVELOPERS" type="add">48574 - further XWPF support for tables, paragraphs, including enhanced support for adding new ones</action>
|
||||||
|
@ -233,14 +233,14 @@ public class DataFormatter {
|
|||||||
int at = formatStr.indexOf(colour);
|
int at = formatStr.indexOf(colour);
|
||||||
if(at == -1) break;
|
if(at == -1) break;
|
||||||
String nFormatStr = formatStr.substring(0,at) +
|
String nFormatStr = formatStr.substring(0,at) +
|
||||||
formatStr.substring(at+colour.length()+1);
|
formatStr.substring(at+colour.length());
|
||||||
if(nFormatStr.equals(formatStr)) break;
|
if(nFormatStr.equals(formatStr)) break;
|
||||||
|
|
||||||
// Try again in case there's multiple
|
// Try again in case there's multiple
|
||||||
formatStr = nFormatStr;
|
formatStr = nFormatStr;
|
||||||
colourM = colorPattern.matcher(formatStr);
|
colourM = colorPattern.matcher(formatStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to extract special characters like currency
|
// try to extract special characters like currency
|
||||||
Matcher m = specialPatternGroup.matcher(formatStr);
|
Matcher m = specialPatternGroup.matcher(formatStr);
|
||||||
while(m.find()) {
|
while(m.find()) {
|
||||||
|
@ -77,6 +77,44 @@ public class TestDataFormatter extends TestCase {
|
|||||||
assertEquals("[ab]12.34[x]", dfUS.formatRawCellContents(12.343, -1, "[ab]##.##[x]"));
|
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.
|
* Test how we handle negative and zeros.
|
||||||
* Note - some tests are disabled as DecimalFormat
|
* Note - some tests are disabled as DecimalFormat
|
||||||
|
Loading…
Reference in New Issue
Block a user