WernerBeinhart
WernerBeinhart

Reputation: 28

How to change the background color of an Excel sheet cell in C#

How can I change the background color of an Excel sheet cell with C#?

enter image description here

Upvotes: 0

Views: 2668

Answers (1)

I would do it that way:

xlWorksheet.Cells[1, 1].Interior.Color = Excel.XlRgbColor.rgbRed;

But don't forget to declare the right using:

using Excel = Microsoft.Office.Interop.Excel;

And I declared the following variables

Excel.Application xlApplication;
Excel.Workbook xlWoorkbook;
Excel.Worksheet xlWorksheet;

xlApplication = new Excel.Application();
xlWoorkbook = xlApplication.Workbooks.Add();
xlWorksheet = xlWoorkbook.Worksheets[1];

Hopefully that works for you too!

Upvotes: 4

Related Questions