Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 576
reddy Avatar asked Sep 07 '11 13:09

reddy


People also ask

How do I change the background color of a row in Excel?

Select the cell or range of cells you want to format. Click Home > Format Cells dialog launcher, or press Ctrl+Shift+F. On the Fill tab, under Background Color, pick the color you want.

How do I change the background color of a cell in Excel using Apache POI?

Apache POI provides three methods for changing the background color. In the CellStyle class, we can use the setFillForegroundColor, setFillPattern, and setFillBackgroundColor methods for this purpose. A list of colors is defined in the IndexedColors class. Similarly, a list of patterns is defined in FillPatternType.


1 Answers

straight from the official guide:

    // Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
row.setRowStyle(style);
like image 109
karla Avatar answered Sep 18 '22 14:09

karla