我能够从 Excel 工作表中获取值,我的工作表中有 20 列,其中第 7 列和第 8 列是日期类型单元格,例如 2015 年 3 月 7 日,我能够获取字符串/文本值正确,但无法获取日期格式单元格,并收到错误,我尝试更改类型以获取单元格值但没有发生,任何人都可以帮助我如何获取文本/字符串或日期格式while 循环中的单元格,'
我的代码如下,
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Map<Field, String> values = new EnumMap(Field.class);
for (Field f : Field.values()) {
Cell cell = nextRow.getCell(f.ordinal());
if (cell != null) {
values.put(f, cell.getStringCellValue());
}
}
日期格式为2015 年 3 月 7 日
最佳答案
尝试检查单元格的格式,然后使用正确的函数提取值,
供引用,
if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){
if (DateUtil.isCellDateFormatted(cell)) {
System.out.println(cell.getDateCellValue());
} else {
System.out.println(cell.getNumericCellValue());
}
}
关于java - 在 Java 中从 Excel 中获取值的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32547398/