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

后端 未结 4 1753
无人共我
无人共我 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:52

    A better way to set it now using POI is to use the BuiltinFormats class.

    Eg:

    To convert the column type to numeric

     CellStyle numericStyle = workbook.createCellStyle(); 
     numericStyle.setDataFormat(BuiltinFormats.getBuiltinFormat(2)); // 2 For Number 
     worksheet.setDefaultColumnStyle(colId, numericStyle);
    

    The complete list of BuiltinFormats formats can be seen, here

提交回复
热议问题