【问题标题】:Read Date as string from excel using apache poi使用apache poi从excel中读取日期作为字符串
【发布时间】:2015-07-15 23:37:17
【问题描述】:

我正在尝试使用 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;
    }
}

我正在以 的奇怪形式获取日期。单元格值 id 3/12/2015。任何人都可以请指导我。

【问题讨论】:

  • 你试过 cell.getDateCellValue());

标签: java apache-poi


【解决方案1】:

而不是 DateFormatter 只需像这样重写:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 2014-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    相关资源
    最近更新 更多