This project is read-only.

Set row color

Jun 21, 2011 at 10:09 PM

First of all, great project.

Now, I only see the cell bg color.  Is there a way to set the background color for a row?  How about alternate row background color?



Jun 22, 2011 at 1:29 PM

Have you checked out the tutorials?  The one called FilLBackgroundInXls should get you what you need.  I think in order to alternate you will have to give a different style to each row though and keep track of which is what.  

Jun 22, 2011 at 6:43 PM

Thanks majnun,

I have read all the example projects.  The FillBackgroundInXls only shows us to fill up per cell, not the whole row. 

Of course, I can apply each cell in a specific row with bgcolor with the even row sequence as work-around. It will be quite a mess.   However, I would think it would be a good built-in function for this row alternate bgcolor.

Any other suggestion, Experts?


Jun 23, 2011 at 2:12 PM

I don't think there is a general field you can set for the entire sheet to alternate (I'm certainly not an expert).  But I didn't mean you had to set the style for each cell in the row.  You can set a style for the row itself.  Depending on how you are generating your rows that might not be an inconvenience.  

Jun 23, 2011 at 6:37 PM

Once again, thanks majnun for your response.

It is interesting that you indicate we can set the style for the row itself.  I want to know about this but I could not find where.  As far as I know, the style is only applied to cell, not row.

Your help is appreciated.



Jun 23, 2011 at 8:42 PM

I haven't been able to doublecheck today, but can't you take your row x and do x.RowStyle = StyleWhatever ? I thought it worked the same way as CellStyle and it applies to all the cells in the row

Jun 23, 2011 at 11:16 PM
Normally, I loop over all the cells and add a common style.  It has the same effect as applying it to the row, except the color stops at the last cell of data.


                    CellStyle headerCellStyle = workbook.CreateCellStyle();

                    headerCellStyle.FillForegroundColor = HSSFColor.GREY_25_PERCENT.index;

                    headerCellStyle.FillPattern = FillPatternType.SOLID_FOREGROUND;

                    Row additionalHeaderRow = sheet.CreateRow(0);

                    for (int h = 0; h < headerRow.LastCellNum; h++)                     {
                          // Apply Cell Style
Jun 19, 2014 at 9:05 PM
Hi, I have a similar question.
RowStyle change the row style, but, I want to apply only in the already created cells.
But if apply the style after create the cells look what happens.


But I need only the created cells be formated.
I know that I can use CellStyle property, but in this case is not the better solutions,


Your help is appreciated.