使用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;
}
0 意見:
張貼留言