Bhavani
Bhavani

Reputation: 27

How to add color to a cell in an excel sheet using C# COM Interop

I'm using C# COM Interop to create and update Excel files on the fly. I used the below code. But I'm not sure how to add color to a particular cell. Please help me with the same.

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application excel = new Excel.Application();
excel.Visible = true;
Excel.Workbook wb = excel.Workbooks.Open(excel_filename);
Excel.Worksheet sh = wb.Sheets.Add();
sh.Name = "TestSheet";
sh.Cells[1, "A"].Value2 = "SNO";
sh.Cells[2, "B"].Value2 = "A";
sh.Cells[2, "C"].Value2 = "1122";
wb.Close(true);
excel.Quit();  

Upvotes: 1

Views: 566

Answers (1)

Mir
Mir

Reputation: 126

Try this
wb.Cells[row, clmn].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)

Upvotes: 1

Related Questions