java poi读取整数_POI将Excel字符串读取为数字

我正在使用Apache POI读取Excel文件。在阅读时,我注意到它将字符串作为浮点值。

如果我的单元格包含1,则它将获取为1.0

我从以前的问题中得到了一些提示,并修改了代码,但float表示仍然保持原样。

如何正确读取字符串和日期的数据?

DataFormatter df = new DataFormatter();

for (Row row : sheet) {

for(int cn=0; cn

// If the cell is missing from the file, generate a blank one

// (Works by specifying a MissingCellPolicy)

Cell cell = row.getCell(cn, Row.CREATE_NULL_AS_BLANK);

// Print the cell for debugging

cell.setCellType(Cell.CELL_TYPE_STRING);

System.out.println("CELL: " + cn + " --> " + df.formatCellValue(cell));

if (row.getRowNum() == 0) {

sheetColumnNames.add(cell.getRichStringCellValue().getString());

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值