]> source.dussan.org Git - poi.git/commitdiff
Fix bug #52369 - Event based XSSF parsing should handle formatting of formula values...
authorNick Burch <nick@apache.org>
Tue, 20 Dec 2011 05:34:58 +0000 (05:34 +0000)
committerNick Burch <nick@apache.org>
Tue, 20 Dec 2011 05:34:58 +0000 (05:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1221103 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java

index 735eedfbae7a6f51ad85cd081683c44d645da3de..40fe9bb2efd43bcc17c2c67e0734b116c81208db 100644 (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>
index 1c6018c13b0b102a97aebf64d97171d5e0b60225..5d7e2dcaa736485892b5f5575986a4238bcc9f54 100644 (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;