Apache POI for Excel: Setting the cell type to “text” for an entire column

后端 未结 4 1714
无人共我
无人共我 2021-02-20 17:37

I need to generate an .xls (Excel) file, using the Java library Apache POI for spreadsheets.

The file will contain a list of phone numbers in column A, formatted as \"02

4条回答
  •  北海茫月
    2021-02-20 17:50

    Here's some example code inspired by Vlad's answer:

    DataFormat fmt = workbook.createDataFormat();
    CellStyle textStyle = workbook.createCellStyle();
    textStyle.setDataFormat(fmt.getFormat("@"));
    worksheet.setDefaultColumnStyle(0, textStyle);
    

    The above code sets the default style for the first column of worksheet to TEXT.

    Thanks, Vlad!

提交回复
热议问题