public static String getCellValue(Cell cell) {
int cellType = cell.getCellType();
String cellValue = "";
switch (cellType) {
case HSSFCell.CELL_TYPE_NUMERIC:
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
try {
cellValue = cell.getStringCellValue();
} catch (IllegalStateException e) {
cellValue = String.valueOf(cell.getNumericCellValue());
}
break;
default:
cellValue = cell.getStringCellValue();
}
return cellValue.trim();
}java poi读取Excel里面含有公式的单元格的值
最新推荐文章于 2024-11-06 09:45:56 发布
本文介绍了一种从Excel单元格中获取值的方法,包括数值、公式和字符串类型的处理方式,并确保返回值已去除首尾空白。

378





