Rajesh D
Rajesh D

Reputation: 177

c# - Interior.Color not working

using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;

Code

oSheet = (Excel.Worksheet)oWB.ActiveSheet;
oSheet.Name = "Data";
oSheet.Cells[1, 1].Interior.Color = 4;

My goal to get the cell value and need to set Background color to color index 4.

Example.

If cell[5,2] contain Text as "NO", need to set set Background color to color. index 4.

But I am getting error as

does not contain a definition for 'Interior' and no extension method 'Interior' accepting a first argument of type 'object' could be found

Upvotes: 0

Views: 1892

Answers (1)

Urknecht
Urknecht

Reputation: 413

I haven't tested it myself but if you want to use Color than you have to use RGB values. But be carefull since B and R are switched, so you have to use B G R to set your Color.

If you want to use your color index 4 then use ColorIndex instead.

oSheet.Cells[1, 1].Interior.ColorIndex = 4;

Upvotes: 1

Related Questions