0

我需要从 Excel 文件中获取单元格数据,因为它们看起来像并撞到DataFormatter了 Apache PO 类。除了包含日期的单元格之外,这就像一个魅力。下面是我的代码:

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

例如,一个单元格包含 5/3/2013,我只得到 5/3/13。有什么解决方案吗?

4

1 回答 1

3

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

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.

于 2013-06-24T18:11:17.740 回答