Excel获取数值篇
修复Cell.getCellType方法过时问题
使用最新的类型方式获取
根据Excel单元格类型返回相对应的值
/**
* 根据Excel单元格类型返回相对应的值
* @param cell
* @return
*/
public static Object getValueByType(Cell cell) {
if (cell==null || "".equals(cell.toString().trim())) {
return "";
}
Object cellValue = new Object();
try {
if(cell.getCellTypeEnum() == CellType.FORMULA || cell.getCellTypeEnum()==CellType.NUMERIC) {
double temp = cell.getNumericCellValue();
DecimalFormat df = new DecimalFormat("0.##");
cellValue = df.format(temp);
}else if(cell.getCellTypeEnum() == CellType.STRING) {
cellValue = String.valueOf(cell);
}else {
cellValue = "";
}
} catch (Exception e) {
e.printStackTrace();
}
return cellValue;
}