How do I set cell value to Date and apply default Excel date format?

前端 未结 6 1683
天涯浪人
天涯浪人 2020-11-29 21:33

I\'ve been using Apache POI for some time to read existing Excel 2003 files programmatically. Now I have a new requirement to create entire .xls files in-memory (still using

6条回答
  •  时光取名叫无心
    2020-11-29 22:00

    http://poi.apache.org/spreadsheet/quick-guide.html#CreateDateCells

    CellStyle cellStyle = wb.createCellStyle();
    CreationHelper createHelper = wb.getCreationHelper();
    cellStyle.setDataFormat(
        createHelper.createDataFormat().getFormat("m/d/yy h:mm"));
    cell = row.createCell(1);
    cell.setCellValue(new Date());
    cell.setCellStyle(cellStyle);
    

提交回复
热议问题