From 9250a2e01971d777dbcb9d4eaa34aba511fe29a3 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 20 Dec 2011 05:34:58 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/status.xml | 1 + .../xssf/eventusermodel/XSSFSheetXMLHandler.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 735eedfba..40fe9bb2e 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52369 - Event based XSSF parsing should handle formatting of formula values in XSSFSheetXMLHandler 52348 - Avoid exception when creating cell style in a workbook that has an empty xf table 52219 - fixed XSSFSimpleShape to set rich text attributes from XSSFRichtextString 52314 - enhanced SheetUtil.getColumnWidth diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java index 1c6018c13..5d7e2dcaa 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java @@ -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;