[prev in list] [next in list] [prev in thread] [next in thread] 

List:       poi-user
Subject:    Fwd: issue with HSSFCell.getStringCellValue()
From:       Sanjiv Jivan <sanjiv.jivan () gmail ! com>
Date:       2005-04-28 18:02:21
Message-ID: a17839be05042811023dff7c64 () mail ! gmail ! com
[Download RAW message or body]


I found that the cell that POI was raising an exception complaining that its 
a numeric field is actually marked as 'Text' type and not 'Number' (ie when 
I right click on cell --> Format Cells-->Number tab. : Type is 'Text').


---------- Forwarded message ----------
From: Sanjiv Jivan <sanjiv.jivan@gmail.com>
Date: Apr 28, 2005 1:56 PM
Subject: issue with HSSFCell.getStringCellValue()
To: POI Users List <poi-user@jakarta.apache.org>

I have a spreadsheet with a postal code column. In my app, we treat postal 
codes as Strings.

The problem is that when reading the postal code cell values from the 
spreadsheet using HSSFCell.getStringCellValue(), it raises an exception when 
the postal code happens to contain only numbers. Excel might be converting 
the data type to number for such cells implicitly but there's no reason that 
I should not be able to read these as Strings. I think that the 
getStringCellValue() should simply read the value as number and do a 
toString() and return instead of raising an exception.

From org.apache.poi.hssf.usermodel.HSSFCell :

public String getStringCellValue()
{
if (cellType == CELL_TYPE_BLANK)
{
return "";
}
if (cellType == CELL_TYPE_NUMERIC)
{ 
throw new NumberFormatException(
"You cannot get a string value from a numeric cell");
}
if (cellType == CELL_TYPE_BOOLEAN)
{
throw new NumberFormatException( 
"You cannot get a string value from a boolean cell");
}
...
...
}

Let me know your thoughts.

Thanks,
Sanjiv


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic