【问题标题】:Writing Dates Using POI Tutorial使用 POI 教程编写日期
【发布时间】:2013-01-10 18:43:54
【问题描述】:

我正在通过以下教程在 Excel 表中使用 poi API 编写日期 http://poi.apache.org/spreadsheet/quick-guide.html#CreateDateCells 但是当我尝试运行代码时,提交的日期显示“###”而不是实际日期!! 这是代码sn-p

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

【问题讨论】:

    标签: apache-poi


    【解决方案1】:

    当单元格的格式设置为结果文本太长而无法在单元格中显示所有内容时,Excel 会显示一个充满“#”符号的单元格(例如“########”) .当您在 Excel 中打开电子表格时,将列加宽足够长,它将显示格式化的日期。

    要让 POI 以这样的方式创建电子表格,使列从一开始就足够宽,那么您需要自己设置列宽。

    sheet.setColumnWidth(columnIndex, width)
    

    在传入之前将宽度乘以 256,因为此方法使用的宽度单位是字符的 1/256。这是 Javadoc:Sheet

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多