java导入excel包含公式的处理方法
CELL_TYPE_FORMULA的cell时 ,取的是计算出来的值,不是取公式,所以不能用cell.getCellFormula()
取计算出来的值,就要判断值的类型,用这个函数cell.getCachedFormulaResultType()
switch (cell.getCachedFormulaResultType()) {
case STRING:
cellValue = cell.getStringCellValue();
break;
case NUMERIC:
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);
cellValue = String.valueOf(nf.format(cell.getNumericCellValue()));
break;
case BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
default:
cellValue = cell.getCellFormula();
}