![](/img/trans.png)
[英]How to assign System.Drawing.Color to Microsoft.Office.Interop.Excel.ColorFormat
[英]How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
我正在为 Excel 开发 vsto 插件,我正在尝试将颜色更改为 Excel 中的注释。
这是我拥有的代码:
Excel.Range activeCell = _application.ActiveCell;
activeCell.AddComment("some text"));
activeCell.Comment.Shape.Fill.BackColor = Color.Red;
我得到的例外是:
无法将类型“System.Drawing.Color”隐式转换为“Microsoft.Office.Interop.Excel.ColorFormat”
我找不到如何在两种格式之间进行转换。
一种选择是使用ColorTranslator.ToOle
int oleColor = ColorTranslator.ToOle(Color.Red);
activeCell.Comment.Shape.Fill.BackColor.RGB = oleColor;
试试这个:
activeCell.Comment.Shape.Fill.BackColor = XlRgbColor.rgbRed;
或者这个(编辑:错误):
activeCell.Comment.Shape.Fill.BackColor.RGB = Color.FromRgb(255,0,0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.