Just in case someone chances upon this post, the solution is as follows:

if(rowIndex % 2 == 0) {
                                color = IndexedColors.AQUA.index;
                        }else {
                                color = IndexedColors.WHITE.index;
                        }
colorCell(cell, color);

and then in colorCell,

private void colorCell(Cell cell, short color) {
                CellStyle cellStyle = cell.getCellStyle();
                CellStyle newStyle = wb.createCellStyle();
                newStyle.cloneStyleFrom(cellStyle);
                newStyle.setFillForegroundColor((short) color);
                newStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
                cell.setCellStyle(newStyle);
        }

make sure you create a new style by cloning whatever style you had earlier.
Do the alternate coloring of rows in the end after you have completed other
styling



--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Needs-help-regarding-coloring-alternate-rows-tp2296869p5710294.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to