【发布时间】:2016-05-12 09:25:08
【问题描述】:
我正在使用 apache poi 3.14 创建一个 excel 文件,该文件必须包含不同类型的数据,包括日期。
我的代码在大多数情况下都能正常工作。 在单元格中编写具体日期(java.util.Date)时遇到问题。 这是我的代码:
Date date;
// code where I get the value of date
Cell currentCell = currentRow.createCell(fieldPos++);
// line below doesn't work for date like '11/11/1811' but work for '11/11/2111'
currentCell.setCellValue(date);
currentCell.setCellStyle(myDateStyle);
假设我有 3 个日期要写:
- 01/01/2009
- 2111 年 11 月 11 日
- 11/11/1811
我的 excel 文件将如下所示:
| 2009 年 1 月 1 日 | 2111 年 11 月 11 日 | 空白单元格 |
当日期等于 11/11/1811 时 currentCell.setCellValue(date) 行将值设置为 -1,因此在我的 excel 文件中它显示为空白(根据我的 dateStyle)
为什么它在特定日期不起作用,我该如何解决?
【问题讨论】:
标签: java excel date apache-poi