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

前端 未结 6 1695
天涯浪人
天涯浪人 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:09

    To set to default Excel type Date (defaulted to OS level locale /-> i.e. xlsx will look different when opened by a German or British person/ and flagged with an asterisk if you choose it in Excel's cell format chooser) you should:

        CellStyle cellStyle = xssfWorkbook.createCellStyle();
        cellStyle.setDataFormat((short)14);
        cell.setCellStyle(cellStyle);
    

    I did it with xlsx and it worked fine.

提交回复
热议问题