改之前的代码
switch (cell.getCellType()) {
// case Cell.CELL_TYPE_NUMERIC:
// if (HSSFDateUtil.isCellDateFormatted(cell)) {
// cellValue = DateFormatUtils.format(cell.getDateCellValue(), “yyyy-MM-dd”);
// } else {
// NumberFormat nf = NumberFormat.getInstance();
// cellValue = String.valueOf(nf.format(cell.getNumericCellValue())).replace(",", “”);
// }
// break;
// case Cell.CELL_TYPE_STRING:
// cellValue = String.valueOf(cell.getStringCellValue());
// break;
// case Cell.CELL_TYPE_BOOLEAN:
// cellValue = String.valueOf(cell.getBooleanCellValue());
// break;
// case Cell.CELL_TYPE_ERROR:
// cellValue = “错误类型”;
// break;
// default:
// cellValue = “”;
// break;
// }
改之后的代码
if(cell.getCellTypeEnum() == CellType.NUMERIC){
if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = DateFormatUtils.format(cell.getDateCellValue(), “yyyy-MM-dd”);
} else {
NumberFormat nf = NumberFormat.getInstance();
cellValue = String.valueOf(nf.format(cell.getNumericCellValue())).replace(",", “”);
}
}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 = “”;
}
参考文档:http://poi.apache.org/apidocs/3.17/