- private String getCellValue(HSSFCell cell) {
- String cellValue = "";
- DecimalFormat df = new DecimalFormat("#");
- switch (cell.getCellType()) {
- case HSSFCell.CELL_TYPE_STRING:
- cellValue = cell.getRichStringCellValue().getString().trim();
- break;
- case HSSFCell.CELL_TYPE_NUMERIC:
- cellValue = df.format(cell.getNumericCellValue()).toString();
- break;
- case HSSFCell.CELL_TYPE_BOOLEAN:
- cellValue = String.valueOf(cell.getBooleanCellValue()).trim();
- break;
- case HSSFCell.CELL_TYPE_FORMULA:
- cellValue = cell.getCellFormula();
- break;
- default:
- cellValue = "";
- }
- return cellValue;
- }
poi导入excel判断单元格类型及转换
最新推荐文章于 2021-07-26 22:38:42 发布
本文介绍了一个用于解析Excel单元格值的Java方法,该方法能够根据单元格类型(字符串、数值、布尔值、公式)正确获取并转换单元格内容。适用于处理Excel文件时的数据提取。

1615

被折叠的 条评论
为什么被折叠?



