poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sanjiv Jivan <sanjiv.ji...@gmail.com>
Subject issue with HSSFCell.getStringCellValue()
Date Thu, 28 Apr 2005 17:56:21 GMT
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

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