我正在使用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());
}
}
}
1万+

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



