excel 导入科学计算发的处理
一般的导入都会有这个问题,类型转换的时候,用下面的代码
java
public static String getCellValueAsString(Cell cell) {
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case STRING:
return cell.getStringCellValue();
case NUMERIC:
// 判断是否为整数
double value = cell.getNumericCellValue();
DecimalFormat decimalFormat;
if (value == Math.floor(value)) {
// 整数,去掉小数点
decimalFormat = new DecimalFormat("0");
} else {
// 小数,保留小数位
decimalFormat = new DecimalFormat("0.##########");
}
return decimalFormat.format(value);
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case FORMULA:
return cell.getCellFormula();
default:
return "";
}
}