Bug 15303

Summary: [Patch] [RFE] cell.getCellValue(); cell.setCellValue();
Product: POI Reporter: Holger Schulz <hsapache>
Component: HSSFAssignee: POI Developers List <dev>
Severity: enhancement    
Priority: P3    
Version: 2.0-dev   
Target Milestone: ---   
Hardware: All   
OS: other   
Attachments: Modified from POI 1.5.1
JUnit Test for modification to 1.5.1 HSSFCell file.
Partial implementation of the proposed feature.

Description Holger Schulz 2002-12-12 10:24:44 UTC

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 
        case HSSFCell.CELL_TYPE_NUMERIC:
            return new Double(_cell.getNumericCellValue());
        case HSSFCell.CELL_TYPE_STRING:
            return _cell.getStringCellValue();
            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
Comment 1 Avik Sengupta 2002-12-12 11:17:16 UTC
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?
Comment 2 Andy Oliver 2002-12-12 12:07:23 UTC
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).
Comment 3 Donald Bell 2003-03-31 04:59:16 UTC
Created attachment 5569 [details]
Modified from POI 1.5.1
Comment 4 Donald Bell 2003-03-31 04:59:58 UTC
Created attachment 5570 [details]
JUnit Test for modification to 1.5.1 HSSFCell file.
Comment 5 Donald Bell 2003-03-31 05:01:59 UTC
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.
Comment 6 Donald Bell 2003-05-09 05:09:01 UTC
Created attachment 6290 [details]
Partial implementation of the proposed feature.
Comment 7 Donald Bell 2003-05-09 05:10:05 UTC
Created attachment 6291 [details]
Comment 8 Andy Oliver 2003-07-24 14:05:04 UTC
its partial...its not in contrib....