简体   繁体   English

C#-Interior.Color不起作用

[英]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. 我的目标是获取单元格值,需要将背景色设置为颜色索引4。

Example. 例。

If cell[5,2] contain Text as "NO", need to set set Background color to color. 如果cell [5,2]包含Text为“ NO”,则需要将设置的背景色设置为color。 index 4. 索引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. 我自己还没有测试过,但是如果要使用Color ,则必须使用RGB值。 But be carefull since B and R are switched, so you have to use BGR to set your Color . 但是要小心,因为B和R已切换,因此您必须使用BGR设置您的Color

If you want to use your color index 4 then use ColorIndex instead. 如果要使用颜色索引4,请改用ColorIndex

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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