poi-4.x中获取单元格数据类型

it2022-05-05  107

所使用的部分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; } ......

最新回复(0)