Bug 45404 - [PATCH] New class to obtain formatted cell values
Summary: [PATCH] New class to obtain formatted cell values
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-15 20:49 UTC by James
Modified: 2008-07-20 10:19 UTC (History)
0 users



Attachments
enhancement source code in zip archive (10.35 KB, application/octet-stream)
2008-07-15 20:51 UTC, James
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James 2008-07-15 20:49:21 UTC
HSSFDataFormatter contains methods for formatting the value stored in an HSSFCell. This can be useful for reports and GUI presentations when you need to display data exactly as it appears in Excel. Supported formats include currency, SSN, percentages, decimals, dates, phone numbers, zip codes, etc. 


Usage:

HSSFCell cell = row.getCell(0);
HSSFDataFormatter fomatter = new HSSFDataFormatter();
String formattedStr = formatter.formatCellValue(cell);

-This yields a formatted string based on the cell type & format:
-CELL_TYPE_STRING = returns string value as is
-CELL_TYPE_BOOLEAN = returns "true" or "false"
-CELL_TYPE_BLANK = returns ""
-CELL_TYPE_FORMULA = cell formula string
-CELL_TYPE_NUMERIC = formatted value i.e. "$1,000.00 USD", "61.54%", "Thursday, January 02, 2003"

-There's also an overloaded method that takes a FormulaEvaluator:

String formattedStr = formatter.formatCellValue(cell, evaluator);

-CELL_TYPE_FORMULA = cell formula is evaluated, then formatted
-All other cell types = same as above
Comment 1 James 2008-07-15 20:51:19 UTC
Created attachment 22262 [details]
enhancement source code in zip archive
Comment 2 Nick Burch 2008-07-20 10:19:34 UTC
Thanks for this code. I've applied it to svn

(Had to do a few tweaks to make it play nicely with java 1.4, then some more so that it could work with the eventusermodel stuff, but most of it is unchanged!)