简体   繁体   中英

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

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 BGR to set your Color .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM