使用Apache POI从Excel中读取日期字符串

3
我正在尝试使用Apache POI库读取Excel。我想将日期字段转换为字符串值。因此,我使用了以下代码:
if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){
    if(DateUtil.isCellDateFormatted(cell)){
       DataFormatter df = new DataFormatter();
       FormulaEvaluator fe = Workbook.getCreationHelper().createFormulaEvaluator();
       String str= formatter.formatCellValue(cell, fe);
       return str;
    }
}

我得到的日期格式很奇怪,是<3/12/[]15>。单元格的值为3/12/2015。请问有人可以指导我吗。


你尝试过使用cell.getDateCellValue()吗? - anish
1个回答

0

不要只是简单地重写DateFormatter:

if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){
    String date = cell.getDateCellValue();
   }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接