Styles API POI

1

I have:

CellStyle style = sheet.getWorkbook().createCellStyle();

HSSFCell cell = row.createCell((short)number);
cell.setCellValue(text)
cell.setCellStyle(style);

I would like the background to be gray, for example

    
asked by sirdaiz 28.04.2017 в 12:32
source

2 answers

1

What you have to do is:

CellStyle style = sheet.getWorkbook().createCellStyle();

//cambiar el fondo
style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);

HSSFCell cell = row.createCell((short)number);
cell.setCellValue(text)
cell.setCellStyle(style);
    
answered by 28.04.2017 / 12:34
source
0

With this method you can add the color.

protected CellStyle setCellBackground(CellStyle cellStyle, Short color) {
    cellStyle.setFillForegroundColor(color);
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    return cellStyle;
}

For the gray color it is:

HSSFColor.GREY_25_PERCENT.index
    
answered by 31.10.2017 в 00:21