public static String getValue(HSSFCell cell){
if (null != cell) {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC: // 数字
return cell.getNumericCellValue()
+ " ";
case HSSFCell.CELL_TYPE_STRING: // 字符串
return cell.getStringCellValue()
+ " ";
case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean
return cell.getBooleanCellValue()
+ " ";
case HSSFCell.CELL_TYPE_FORMULA: // 公式
return cell.getCellFormula() + " ";
case HSSFCell.CELL_TYPE_BLANK: // 空值
return "";
case HSSFCell.CELL_TYPE_ERROR: // 故障
return "";
default:
return "未知类型 ";
}
}else{
return "";
}
}
下面这个是自己修改的
public String getValue(XSSFCell cell) {
if (null != cell) {
switch (cell.getCellTypeEnum()) {
case NUMERIC: // 数字
DecimalFormat df = new DecimalFormat("0");//处理科学计数法
String val = df.format(cell.getNumericCellValue());
return val;
case STRING: // 字符串
return cell.getStringCellValue() + "";
case BOOLEAN: // Boolean
return cell.getBooleanCellValue() + "";
case FORMULA: // 公式
return cell.getCellFormula() + " ";
case BLANK: // 空值
return "";
case ERROR: // 故障
return "";
default:
return "未知类型 ";
}
} else {
return "";
}
}
传入HSSFCell 或者 Cell
JAVA导入excel 表格处理单元格不同类型的取值存入数据库
最新推荐文章于 2024-07-03 14:13:18 发布