excel poi 导入手机号码和日期_使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10...

本文介绍了一种从Excel文件中读取不同类型的单元格数据的方法,包括数值型、日期型、字符串型等,并提供了具体的Java代码实现。通过判断单元格类型,实现了对不同类型数据的正确读取和转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#2 得分:0回复于: 2010-09-13 17:41:35

if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {

DateFormat format = new SimpleDateFormat(DateUtil.YYYY_MM_DD);

if(HSSFDateUtil.isCellDateFormatted(cell)) {

// 是否为日期型

str = format.format(cell.getDateCellValue());

} else {

// 是否为数值型

double d = cell.getNumericCellValue();

if (d - (int) d 

// 是否为int型

str = Integer.toString((int) d);

} else {

System.out.println("double.....");

// 是否为double型

str = Double.toString(cell.getNumericCellValue());

}

}

System.out.println("type=="+cell.getCellType() );

System.out.println("cell=="+str);

}else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {

str = cell.getRichStringCellValue().getString();

}else if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {

str = cell.getCellFormula();

}else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {

str = " ";

}else if (cell.getCellType() == HSSFCell.CELL_TYPE_ERROR) {

str = " ";

}

这几种 类型  都做判断了   依然还是    1.3471022771E10

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值