Bug 45404

Summary: [PATCH] New class to obtain formatted cell values
Product: POI Reporter: James <james.may>
Component: HSSFAssignee: POI Developers List <dev>
Severity: enhancement    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: enhancement source code in zip archive

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. 


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!)