Changing cell color using apache poi

后端 未结 5 2001
名媛妹妹
名媛妹妹 2020-12-05 14:08

I\'m using Apache POI to read data in a spreadsheet of part numbers. I look up the part number in our database, if we have a CAD drawing of the part I color the part number

5条回答
  •  失恋的感觉
    2020-12-05 14:39

    I believe it is because cell.getCellStyle initially returns the default cell style which you then change.

    Create styles like this and apply them to cells:

    cellStyle = (XSSFCellStyle) cell.getSheet().getWorkbook().createCellStyle();
    

    Although as the previous poster noted try and create styles and reuse them.

    There is also some utility class in the XSSF library that will avoid the code I have provided and automatically try and reuse styles. Can't remember the class 0ff hand.

提交回复
热议问题