简体   繁体   English

Apache POI日期dd.MM.yyyy

[英]Apache POI date dd.MM.yyyy

I have problems to get date in right format using apache poi 3.7 According the documentation I have to use the formatCellValue Method from DataFormatter. 我有问题使用apache poi以正确的格式获取日期3.7根据文档我必须使用DataFormatter中的formatCellValue方法。 Here I found a few answers which advise the same, but it don´t works. 在这里,我找到了一些建议相同的答案,但它不起作用。

The excel field shows the date in format dd.MM.yyyy : for ex: 09.06.2010 excel字段以dd.MM.yyyy格式显示日期:例如: 09.06.2010

After using formatCellValue(Cell cell) I get 9/6/10. 使用formatCellValue(Cell cell)后,我得到了9/6/10。 I try DataFormatter and HSSFDataFormatter with and without Local.German or Local.German 我尝试使用和不使用Local.German或Local.German的DataFormatter和HSSFDataFormatter

Here is my code: 这是我的代码:

if( DateUtil.isCellDateFormatted(cell))
{
    HSSFDataFormatter formatter = new HSSFDataFormatter(Locale.GERMAN);
    String temp = formatter.formatCellValue(cell);
    System.out.println(temp);
}

Can somebody help me? 有人能帮助我吗?

I'm not certain, but I think the issue might be that you've overridden the format string of one of the default date formats. 我不确定,但我认为问题可能是你已经覆盖了其中一种默认日期格式的格式字符串。

This was only fixed in POI 3.8 beta 1 (see the changelog ), so I'd suggest you try upgrading to 3.8 beta3 and it will hopefully fix your issue. 这仅在POI 3.8 beta 1中修复(请参阅更改日志 ),因此我建议您尝试升级到3.8 beta3,它有望解决您的问题。 Previously POI just assumed that the default formats wouldn't have been changed, so would use the default format string for them. 以前POI只是假设默认格式不会被更改,因此将使用默认格式字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM