Reputation: 28
How can I change the background color of an Excel sheet cell with C#?
Upvotes: 0
Views: 2668
Reputation: 56
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