I use this code to change the font in excel to color, which I define
Color sColor = new Color (value,0,0);
XSSFColor userColor = new XSSFColor(sColor);
CellStyle style = wb.createCellStyle();
XSSFFont font = wb.createFont();
font.setColor(userColor);
style.setFont(font);
cell.setCellStyle(style);
Can I change the cell’s Background same way.
I saw the question here
Setting background custom color not working for XSSF in Apache POI
And I used the code:
XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));
((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
cell.setCellStyle(cellStyle);
The background still always white.
Am sure that all other parts of the code written properly, because it works when I changed the font.
I have office 2010 on my computer
2
Answers
Thanks all I found solution now
Create cell style object:
Set custom color:
Add style to the cell: