How to set the style for an entire column in EPPlus?

row1 picture row1 · Mar 28, 2013 · Viewed 19.1k times · Source

Is it possible to set the style for an entire column in EPPlus? I would expect that I could just use the Column method, but when I do I get strange results:

//Sets all cells in all columns to Red
worksheet.Column(1).Style.Font.Color.SetColor(Color.Red);

//Sets some cells in column B to red.
worksheet.Column(2).Style.Font.Color.SetColor(Color.Red);

In both cases I am setting the colour after adding some header rows but before adding the bulk of the rows am an not setting the colour anywhere else. I also get similar unexpected results setting the horizontal alignment. At the moment I am resorting to having to set the style at the cell level.

Am I using it incorrectly or is this a bug? Using EPPlus 3.1.2.0 and Excel 2010 (14.0.6129.5000) .

Answer

Jiūtas Brólickaitis picture Jiūtas Brólickaitis · Apr 5, 2016
 int indexOfColumn = ...;
 worksheet.Column(indexOfColumn).Style.Font.Color.SetColor(Color.Red);