private static String getCellValueEvaluator(Cell c) {
if (c == null) return "";
switch (c.getCellType()) {
case FORMULA:
String StringValue = new String();
c.setCellType(CellType.STRING);
StringValue = c.getStringCellValue();
CellStyle ceStyle = c.getCellStyle();
String format = ceStyle.getDataFormatString();
if (format.equals(Constants.PERCENT_FORMAT) && !StringUtils.isEmpty(StringValue)) {
StringValue = ArithUtil.parsePercent(StringValue);
}
return StringValue;
case STRING:
return c.getStringCellValue();
case _NONE:
break;
case NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(c)) {
Date date = c.getDateCellValue();
return DateUtils.getYYYYMMDD_TIMEString(date);
} else {
// 第一种方式
// NumberFormat nf = NumberFormat.getInstance();
// String str = nf.format(c.getNumericCellValue());
// if (str.indexOf(",") >= 0) {
// str = str.replace(",", "");
// }
// return str;
// 第二种方式
c.setCellType(CellType.STRING);
String str = c.getStringCellValue();
return str;
// 这个方式会带有小数点
// return c.getNumericCellValue() + "";
}
case BLANK:
return "";
case BOOLEAN:
break;
case ERROR:
break;
default:
return "unknow type";
}
return "";
}
JAVA解析Excel数字后有小数点
最新推荐文章于 2024-08-23 15:54:50 发布