[英]Changing color of Excel cell throws "'System.__ComObject' does not contain a definition for 'Interior'"
I am currently facing when I want to change the color of my excel sheet.当我想更改我的 excel 表的颜色时,我目前正面临着这种情况。 With my code I am already inserting entries into my excel file.
使用我的代码,我已经将条目插入到我的 excel 文件中。 Some specific cells should receive a special color.
一些特定的单元格应该收到特殊的颜色。
When I run my code, I always get the same error.当我运行我的代码时,我总是得到同样的错误。
Analyzing the Google/Stackoverflow results, I did not find a solution, even though there have been some complaints about this.分析 Google/Stackoverflow 结果,我没有找到解决方案,尽管对此有一些抱怨。
Workbooks wbs = excel.Workbooks;
Workbook sheet = wbs.Open(fileName);
excel.DisplayAlerts = false;
Worksheet y = sheet.ActiveSheet;
y.Copy(y, Type.Missing);
int index = y.Index;
int addRow = 2;
Worksheet x = (Worksheet)excel.Worksheets[index];
//...
//this line throws the error
x.Cells[addRow++, 1].Interior.Color = System.Drawing.Color.Blue;
//...
I am using Microsoft Office Interop which was very useful and did its job...until now.我正在使用 Microsoft Office Interop,它非常有用并且完成了它的工作......直到现在。
You have to use the XlRgbColor to implement Color (for Excel interop 14.0):您必须使用 XlRgbColor 来实现 Color(对于 Excel interop 14.0):
x.Cells[addRow++, 1].Interior.Color = XlRgbColor.xlBlue;
if you have older version: you have to use translator如果您有旧版本:您必须使用翻译器
x.Cells[addRow++, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Silver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.