Fix bug #52369 - Event based XSSF parsing should handle formatting of formula values in XSSFSheetXMLHandler

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1221103 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-12-20 05:34:58 +00:00
parent ac6c00b6df
commit 9250a2e019
2 changed files with 16 additions and 1 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta6" date="2012-??-??">
<action dev="poi-developers" type="fix">52369 - Event based XSSF parsing should handle formatting of formula values in XSSFSheetXMLHandler</action>
<action dev="poi-developers" type="fix">52348 - Avoid exception when creating cell style in a workbook that has an empty xf table</action>
<action dev="poi-developers" type="fix">52219 - fixed XSSFSimpleShape to set rich text attributes from XSSFRichtextString</action>
<action dev="poi-developers" type="fix">52314 - enhanced SheetUtil.getColumnWidth</action>

View File

@ -242,7 +242,21 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
if(formulasNotResults) {
thisStr = formula.toString();
} else {
thisStr = value.toString();
String fv = value.toString();
if (this.formatString != null) {
try {
// Try to use the value as a formattable number
double d = Double.parseDouble(fv);
thisStr = formatter.formatRawCellContents(d, this.formatIndex, this.formatString);
} catch(NumberFormatException e) {
// Formula is a String result not a Numeric one
thisStr = fv;
}
} else {
// No formatter supplied, just do raw value in all cases
thisStr = fv;
}
}
break;