Setting foreground color for HSSFCellStyle is always coming out black

后端 未结 3 635
旧时难觅i
旧时难觅i 2020-12-05 04:09

I am using POI to create an Excel spreadsheet in Java. I have the following code used for creating a header row:

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSh         


        
3条回答
  •  不思量自难忘°
    2020-12-05 04:35

    If you are setting the foreground color, use

    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    

    If you are setting the background color, use

    style.setFillPattern(FillPatternType.THICK_BACKWARD_DIAG);
    

    or

    style.setFillPattern(FillPatternType.THIN_BACKWARD_DIAG);
    

    The foreground and background colors seem to 'stack' (red + blue = purple) if you set the foreground fill pattern before the background fill pattern, but not the other way round. There are several other fill patterns you can choose from. Note that the color will not be applied if you do not change the default fill pattern.

    CellStyle.SOLID_FOREGROUND is deprecated in version 3.15+. Use FillPatternType.SOLID_FOREGROUND instead.

提交回复
热议问题