private static String getCellStringVal(Cell cell, String format) {
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_NUMERIC:
String value;
if (HSSFDateUtil.isCellDateFormatted(cell)) {
Date date = cell.getDateCellValue();
SimpleDateFormat sdf = new SimpleDateFormat(format);
value = sdf.format(date);
} else {
double dValue = cell.getNumericCellValue();
DecimalFormat df = new DecimalFormat("0");
value = df.format(dValue);
}
return value;
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case Cell.CELL_TYPE_BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case Cell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case Cell.CELL_TYPE_BLANK:
return "";
case Cell.CELL_TYPE_ERROR:
return String.valueOf(cell.getErrorCellValue());
default:
return "";
}
}
上面代码中用到的类都是POI的jar包的类,用的时候别导入错了;
POI导入时间过程中变为数字导致错误
最新推荐文章于 2024-09-03 17:27:27 发布