diff options
author | Nick Burch <nick@apache.org> | 2010-06-02 16:51:05 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2010-06-02 16:51:05 +0000 |
commit | 8952570e0bcf435c612b1faffa07f09b51ff562f (patch) | |
tree | 647522bafde1995ea3313a55443cbe58e06757b9 /src/java/org/apache/poi/hssf/extractor | |
parent | 0d1692dbf270fe2aaa2b9c296385b3293d8739b9 (diff) | |
download | poi-8952570e0bcf435c612b1faffa07f09b51ff562f.tar.gz poi-8952570e0bcf435c612b1faffa07f09b51ff562f.zip |
Another fix inspired by bug #48494 - have ExcelExtractor make use of HSSFDataFormatter, so that numbers and dates come out closer to how Excel would render them
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@950657 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hssf/extractor')
-rw-r--r-- | src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java index dc70fef2fb..c2e234ce34 100644 --- a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java +++ b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java @@ -26,7 +26,9 @@ import java.io.PrintStream; import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFComment; +import org.apache.poi.hssf.usermodel.HSSFDataFormatter; import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -51,6 +53,7 @@ import org.apache.poi.ss.usermodel.HeaderFooter; */ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.poi.ss.extractor.ExcelExtractor { private HSSFWorkbook _wb; + private HSSFDataFormatter _formatter; private boolean _includeSheetNames = true; private boolean _shouldEvaluateFormulas = true; private boolean _includeCellComments = false; @@ -60,6 +63,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p public ExcelExtractor(HSSFWorkbook wb) { super(wb); _wb = wb; + _formatter = new HSSFDataFormatter(); } public ExcelExtractor(POIFSFileSystem fs) throws IOException { this(fs.getRoot(), fs); @@ -323,8 +327,9 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p text.append(cell.getRichStringCellValue().getString()); break; case HSSFCell.CELL_TYPE_NUMERIC: - // Note - we don't apply any formatting! - text.append(cell.getNumericCellValue()); + text.append( + _formatter.formatCellValue(cell) + ); break; case HSSFCell.CELL_TYPE_BOOLEAN: text.append(cell.getBooleanCellValue()); @@ -344,7 +349,18 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p } break; case HSSFCell.CELL_TYPE_NUMERIC: - text.append(cell.getNumericCellValue()); + HSSFCellStyle style = cell.getCellStyle(); + if(style == null) { + text.append( cell.getNumericCellValue() ); + } else { + text.append( + _formatter.formatRawCellContents( + cell.getNumericCellValue(), + style.getDataFormat(), + style.getDataFormatString() + ) + ); + } break; case HSSFCell.CELL_TYPE_BOOLEAN: text.append(cell.getBooleanCellValue()); |