因为要做excel的导入导出,发现再导入的时候总是因为科学计数法,公式什么的导致没有取到正确的值,在网上也找到了一些,但是发现都是旧版本的,因此看了一下阿帕奇poi的官方文档进行了一些修改。
下面的是在网上查找的,地址是http://blog.sina.com.cn/s/blog_69398ed90102wdl7.html,时间是2016年
public static String getValue(HSSFCell cell){
下面这个是自己修改的
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 "";
}
}
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 "";
}
}