Frank
Frank

Reputation: 2045

Setting the color of a cell using ExcelPackage

I am using vb.net and I have an asp.net application where I use ExcelPackage. I wanted to know how to set the background color of a particular cell or a row of cells.

Upvotes: 0

Views: 4116

Answers (2)

Ravendarksky
Ravendarksky

Reputation: 633

I know this question is old but here is the answer:

ExcelPackage pck = new ExcelPackage();
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Example");
string index= "A1";
ws.Cells[index].Style.Fill.PatternType = ExcelFillStyle.Solid;    
ws.Cells[index].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Orange);

Please note that you must set the PatternType before you can set a background color or an exception is thrown.

Sorry but my example is c#, you will need to convert to VB.Net to be 100% correct for the question!

Upvotes: 3

Vicente Jr
Vicente Jr

Reputation: 237

I recommend you use the component Epplus, it is quite complete and need not be installed on production server.

http://epplus.codeplex.com/releases/view/42439

Upvotes: 3

Related Questions