我正在通过下面的教程在excel表格http://poi.apache.org/spreadsheet/quick-guide.html#CreateDateCells中使用poi API编写日期,但是当我试图运行代码时,日期字段显示"###“,而不是实际的日期!以下是代码片段
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm"));
Cell cell= row.createCell(4);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
发布于 2013-01-11 04:26:32
当单元格的格式设置为产生的文本太长而无法在单元格中显示所有文本时,Excel会显示充满"#“符号的单元格(例如"########")。当您在Excel中打开电子表格时,将列加宽足够长的时间,它将显示格式化的日期。
要通过POI创建电子表格,使列从一开始就足够宽,则需要自己设置列宽。
sheet.setColumnWidth(columnIndex, width)
在传入之前将宽度乘以256,因为此方法使用的宽度单位是字符的1/256。这是Javadoc:Sheet
https://stackoverflow.com/questions/14265040
复制相似问题