包含日期的单元格上的 DataFormatter 呈现两位数的年份 [英] DataFormatter on cell containing date renders two digits years
本文介绍了包含日期的单元格上的 DataFormatter 呈现两位数的年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 Excel 文件中获取单元格数据,因为它们看起来像 Apache PO 的 DataFormatter
类.除了包含日期的单元格之外,这就像一个魅力.下面是我的代码:
I needed to get cell data from Excel files as they look like and bumped to DataFormatter
class of Apache PO. 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());
}
例如,一个单元格包含 5/3/2013,我只得到 5/3/13.有什么解决办法吗?
For example, a cell contains 5/3/2013, I only get 5/3/13. Would there be any solutions for this?
推荐答案
要以所需格式获取日期,您可以使用以下内容:
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());
现在,如果单元格值为 05/03/2013,它将给出 o/p 为 05/03/2013.我希望这能解决您的问题.
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.
这篇关于包含日期的单元格上的 DataFormatter 呈现两位数的年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文