所使用的部分jar包:
poi-4.0.1.jar
poi-ooxml-4.0.1.jar
poi-ooxml-schemas-4.0.1.jar
poi-scratchpad-4.0.1.jar
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
......
public static String getCellFormatValue(Cell cell){
String cellValue = null;
if (cell != null) {
switch (cell.getCellType()) {
case NUMERIC: {
cellValue = String.valueOf((int) cell.getNumericCellValue());
break;
}
case FORMULA: {
if (DateUtil.isCellDateFormatted(cell)) {
cellValue = cell.getDateCellValue() + "";
} else {
cellValue = String.valueOf(cell.getNumericCellValue());
}
break;
}
case STRING: {
cellValue = cell.getRichStringCellValue().getString();
break;
}
case BLANK: {
cellValue = "";
break;
}
default:
cellValue = "";
}
} else {
cellValue = "";
}
return cellValue;
}
......