poi导入处理单元格过时的方法:
private static String getCellValue(Cell cell) {
if (cell == null || cell.toString().trim().equals("")) {
return "";
}
String cellValue = "";
int cellType=cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_STRING:
cellValue= cell.getStringCellValue().trim();
cellValue= StringUtils.isEmpty(cellValue) ? "" : cellValue;
break;
case Cell.CELL_TYPE_BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
cellValue = new DecimalFormat("#.######").format(cell.getNumericCellValue());
break;
default:
cellValue = "";
break;
}
return cellValue;
}
poi导入处理单元格的最新方法:
private static String getCellValue(Cell cell) {
if (cell == null || cell.toString().trim().equals("")) {
return "";
}
String cellValue = "";
if (cell.getCellTypeEnum() == CellType.NUMERIC) {
cellValue = new DecimalFormat("#.######").format(cell.getNumericCellValue());
} else if (cell.getCellTypeEnum() == CellType.STRING) {
cellValue = String.valueOf(cell.getStringCellValue());
} else if (cell.getCellTypeEnum() == CellType.BOOLEAN) {
cellValue = String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellTypeEnum() == CellType.ERROR) {
cellValue = "错误类型";
} else {
cellValue = "";
}
return cellValue;
}