顯示具有 POI 標籤的文章。 顯示所有文章

使用POI 遇到 java.lang.NumberFormatException: You cannot get a string value from a numeric cell

今天遇到這個問題了,忘了上次怎麼解決的,
本來是

String custModelName = mrow.getCell(CUST_MODEL_NAME).getStringCellValue();

改成

String custModelName = getCellContent(mrow.getCell(CUST_MODEL_NAME));

加一個method
private String getCellContent(HSSFCell cell)
{
String str = null;
if(cell == null) return " ";
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
{
str = String.valueOf(cell.getNumericCellValue());
}
else
{
str = cell.getStringCellValue();
}
return str;
}