从 Java 中的 excel 获取值时出现问题

Issue with fetching value from an excel in Java

我能够从 excel sheet 中获取值,我的 sheet 中有 20 列,其中第 7 列和第 8 列是日期类型的单元格,例如 2015 年 3 月 7 日,我能够正确获取 string/text 值,但无法获取日期格式单元格,出现错误,我尝试更改类型以获取单元格值但没有发生,任何人都可以帮助我如何在我的 while 循环中同时获得 text/String 或日期格式单元格,'

我的代码如下,

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());
                }
            } 

日期格式为 7-Mar-2015

尝试检查单元格的格式,然后使用正确的函数提取值,

供参考,

if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){
        if (DateUtil.isCellDateFormatted(cell)) {
            System.out.println(cell.getDateCellValue());
        } else {
            System.out.println(cell.getNumericCellValue());
        }
}