Color in cell

Hi,

Can you please tell me how we can fill a particular color in background of a cell.

Regards,

Amit

Hi Amit,


Please check the detailed article on how to set the background color of the cell. Following code sets the cell A1 background color to yellow of worksheet sheet2.

Java

//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the added worksheet in the Excel file
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
//Accessing the “A1” cell from the worksheet
Cell cell = cells.get(“A1”);
Style style = cell.getStyle();
//Setting the cell color to yellow
style.setForegroundColor(Color.getYellow());
//Setting the background pattern to vertical stripe
style.setPattern(BackgroundType.SOLID);
//Saving the modified style to the “A1” cell.
cell.setStyle(style);
//Saving the Excel file
workbook.save(“D:/output.xls”);