Hello! If I understand it right I must determine the cell type to call the right getter method for the cell value. Therefore I use this class method: public static Object getCellValue(HSSFCell _cell) { if (null == _cell) { return null; } int nCellType = _cell.getCellType(); switch (nCellType) { case HSSFCell.CELL_TYPE_BLANK: return ""; case HSSFCell.CELL_TYPE_BOOLEAN: return new Boolean(_cell.getBooleanCellValue()); case HSSFCell.CELL_TYPE_ERROR: return new Byte(_cell.getErrorCellValue()); case HSSFCell.CELL_TYPE_FORMULA: throw new NotImplementedYetRuntimeException("CELL_TYPE_FORMULA not supported"); case HSSFCell.CELL_TYPE_NUMERIC: return new Double(_cell.getNumericCellValue()); case HSSFCell.CELL_TYPE_STRING: return _cell.getStringCellValue(); default: throw new RuntimeException("Type " + nCellType + " not supported"); } } I think this should be a method of HSSFCell itself. And a generic setter method would be helpful as well. Thanks for this great library Holger Schulz
Dunno, am personally agnostic to this. Maybe a CellUtil thing? On the other hand, an API should not try to include client code. what say people?
I agree. This is a contrib type thing. Its not particularly conducive to performance (raises object counts and instantiation for one thing). Its something else to maintain for another. I'm not too keen on conveinence functions until after 3.0 or so when the API is stable and we're all bored with HSSF anyhow ;-) (unless Microsoft is nice to us and siginifcantly changes the file format).
Created attachment 5569 [details] Modified from POI 1.5.1
Created attachment 5570 [details] JUnit Test for modification to 1.5.1 HSSFCell file.
I changed the getXXXValue to return values closer to the way that Excel does. I wasn't able to get everything exactly like it Excel does, but it is much closer. If you accept this change I will work further to make the cell to return values like Excel does. I only unit tested this class. The reason for this is that I tried to run the JUnit on the entire site, but it required XLS files that weren't in CVS for me to extract.
Created attachment 6290 [details] Partial implementation of the proposed feature.
Created attachment 6291 [details] UnitTest
its partial...its not in contrib....