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

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

    Vlad: This got most of the problem done. I found that all the empty rows were formatted the way I wanted them. However rows where I had initial zeros looked and worked fine; however if I had to change a pre-existing value with another value starting with zero the zeroes disappeared. So I recommend adding code to when you create the value in the cell to reset the the setCellStyle to text. here are some snippets: method public Cell createCell(Row r!, BBjNumber cell, BBjString value!)

    c!=#this!.createCell(r!, cell)
    c!.setCellValue(value!)
    c!.setCellStyle(#text_format!)
    

    methodret c!

    #text_format! = #wb!.createCellStyle()
    #text_format!.setDataFormat(#format!.getFormat("@"))
    

    methodend

    this may help some other sole searching for initial zeroes. Thank you for posting. Alex

提交回复
热议问题