How to apply background color for the rows in excel sheet using Apache POI?

reddy picture reddy · Sep 7, 2011 · Viewed 58.4k times · Source

I am using Apache POI for exporting data into excel sheet. it works fine. the problem is i need apply yellow background color for few rows in the excel sheet while generating the excel sheet. please hellp me how to apply background color for the rows of excel sheet while generating.

Thanks, Reddy

Answer

karla picture karla · Sep 7, 2011

straight from the official guide:

    // Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
row.setRowStyle(style);