How to apply background color for the rows in excel sheet using Apache POI?
straight from the official guide:
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
row.setRowStyle(style);
//Opening excel file
FileInputStream inputStream = new FileInputStream(new File(excelFileLocation));
XSSFWorkbook resultWorkbook = new XSSFWorkbook(inputStream);
XSSFSheet resultSheet = resultWorkbook.getSheet(sheetName);
//Applying style
XSSFRow sheetrow = resultSheet.getRow(1); // Row number
XSSFCellStyle style = resultWorkbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.GREEN.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
sheetrow.getCell(0).setCellStyle(style);//Cell number
//Saving file
FileOutputStream outFile =new FileOutputStream(new File(excelFile));
resultWorkbook.write(outFile);
outFile.close();