public String getStringCellValue(HSSFCell cell) {
String strCell = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
strCell = cell.getStringCellValue().trim();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
java.text.NumberFormat nf = NumberFormat.getCurrencyInstance();
DecimalFormat df = (DecimalFormat) nf;
df.setDecimalSeparatorAlwaysShown(true);
df.applyPattern("###############");
String value = df.format(new Double(cell.getNumericCellValue()));
strCell = String.valueOf(value);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
strCell = String.valueOf(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
strCell = "";
break;
default:
strCell = "";
break;
}
if (strCell.equals("") || strCell == null) {
return "";
}
if (cell == null) {
return "";
}
return strCell;
}
获取Excel单元格数据内容为字符串类型的数据
最新推荐文章于 2025-08-06 18:40:13 发布
本文介绍了一种从Excel文件中读取单元格数据的方法,并详细解释了如何根据不同的单元格类型(如字符串、数值、布尔值和空白)来转换和获取相应的字符串值。通过使用HSSFCell类的不同方法,如getStringCellValue、getNumericCellValue等,可以有效地处理各种类型的单元格数据。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
1736

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



