nam
nam

Reputation: 23809

How to apply Excel settings only to a range using Epplus

For the values i=4 and i=6, following will apply background color as LightGrey to the entire 4th and 6th rows. Question: Are there any ways so we change the Background color (or any style for that matter) of a row within certain range, say, all the rows from 1st column to the 10th column?

int i;
ExcelRow rowRange = ws.Row(i);
ExcelFill RowFill = rowRange.Style.Fill;
RowFill.PatternType = ExcelFillStyle.Solid;
RowFill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);

Upvotes: 1

Views: 766

Answers (1)

mason
mason

Reputation: 32704

Instead of using ws.Row(rowNumber) use

var firstColumn =  1;
var lastColumn  = 10;
var rowRange    = ws.Cells[rowNumber, firstColumn, rowNumber, lastColumn];
//now do styling on rowRange

rowRange will contain references to all the cells in the rectangle defined by the values you passed to it.

Upvotes: 1

Related Questions