Apache的POI含日期单元格DataFormatter [英] apache poi DataFormatter on cell containing date

查看:2271
本文介绍了Apache的POI含日期单元格DataFormatter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天。

我需要从Excel文件中获取细胞的数据,它们看起来像撞到到 DataFormatter 类的Apache POI的。这就像除了包含日期细胞的魅力。下面是我的code:

I needed to get cell data from excel files as they look like and bumped to DataFormatter class of apache poi. This works like a charm except for cells containing date. Below is my code:

while (rowIterator.hasNext())
{
    Row row = rowIterator.next();

    StringBuilder rowDataBuilder = new StringBuilder();
    int iCellCount = row.getLastCellNum();
    for (int i = 0; i < iCellCount; i++)
    {
        Cell cell = row.getCell(i, Row.CREATE_NULL_AS_BLANK);
        rowDataBuilder.append(dataFormatter.formatCellValue(cell));
        rowDataBuilder.append(" | ");
    }

    _LOG.info("-----> row data: " + rowDataBuilder.toString());
}

例如单元格中包含2013年5月3日,我只得到13年5月3日。会不会有这方面的任何解决方案?谢谢你。

For example a cell contains 5/3/2013, I only get 5/3/13. Would there be any solutions for this? Thanks.

推荐答案

有关在获取所需格式的日期,你可以使用下列内容:

For fetching the date in desired format you can use following:

  SimpleDateFormat DtFormat = new SimpleDateFormat("dd/MM/yyyy");
  Date date=Test.getRow(RowNum).getCell(CellNum).getDateCellValue();
  System.out.println(DtFormat.format(date).toString());

现在,如果单元格的值是2013年5月3日,它会给O / P为2013年5月3日。我希望这将解决您的问题。

And now if the cell value is 05/03/2013, it will give o/p as 05/03/2013. I hope this will resolve your problem.

这篇关于Apache的POI含日期单元格DataFormatter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆