poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Tucker <mtuc...@thoughtbot.com>
Subject Reading XLS zip code +4 cells
Date Fri, 03 Jun 2005 15:40:43 GMT
Hello,

I'm reading data from an XLS sheet using POI. One of the columns 
contains data in the Excel Zip Code + 4 format. However, the values that 
are being returned are not in the correct format. For example, a zip 
code value of 00009-4612 is being returned as 94612. After trying a 
bunch of different things, here's a snippet of what I'm doing now:

HSSFCellStyle zipStyle = hssfworkbook.createCellStyle();
zipStyle.setDataFormat(format.getFormat("00000-0000"));
...
HSSFCell c = row.getCell(zipCol);
c.setCellStyle(zipStyle);
...
if (cellType == HSSFCell.CELL_TYPE_NUMERIC)
{
    Double D = new Double(c.getNumericCellValue());
    Integer I = new Integer(D.intValue());
                   
    double d = D.doubleValue();
    int i = I.intValue();
                   
    if(d > i)
    {
        returnString = D.toString();
    }
                   
    returnString = I.toString();
}
else if (cellType == HSSFCell.CELL_TYPE_STRING) returnString = 
c.getStringCellValue();
else if (cellType == HSSFCell.CELL_TYPE_FORMULA) returnString = 
c.getCellFormula();

I know I'm probably doing something very, very wrong so if someone could 
point me in the right direction, it would be much appreciated. Thanks.

-- 

Matt Tucker
thoughtbot

cell: 617 775 0742
office: 617 876 4780
www.thoughtbot.com


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message