Java中从excel中获取值的问题
我能够从excel工作表中获取值,我的工作表中有20列,其中第7列和第8列是日期类型单元格,如7-Mar-2015,我能够正确获取字符串/文本值,但无法获取日期格式单元格,并且出现错误,我尝试更改类型以获取单元格值,但没有发生,谁能帮我在while循环中如何获取文本/字符串或日期格式的单元格 我的代码如下:Java中从excel中获取值的问题,java,excel,apache-poi,Java,Excel,Apache Poi,我能够从excel工作表中获取值,我的工作表中有20列,其中第7列和第8列是日期类型单元格,如7-Mar-2015,我能够正确获取字符串/文本值,但无法获取日期格式单元格,并且出现错误,我尝试更改类型以获取单元格值,但没有发生,谁能帮我在while循环中如何获取文本/字符串或日期格式的单元格 我的代码如下: while (iterator.hasNext()) { Row nextRow = iterator.next(); Map<Fiel
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());
}
}
while(iterator.hasNext()){
行nextRow=iterator.next();
映射值=新的EnumMap(Field.class);
对于(字段f:Field.values()){
Cell Cell=nextRow.getCell(f.ordinal());
如果(单元格!=null){
value.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());
}
}