如何在C#中从System.Drawing.Color转换为Excel.ColorFormat?更改评论颜色

Dav*_*ero 2 c# excel vsto system.drawing.color excel-addins

我正在为Excel开发一个vsto插件,并且试图将颜色更改为Excel中的注释。

这是我的代码:

Excel.Range activeCell = _application.ActiveCell;
activeCell.AddComment("some text"));
activeCell.Comment.Shape.Fill.BackColor = Color.Red;
Run Code Online (Sandbox Code Playgroud)

我得到的例外是:

无法将类型“ System.Drawing.Color”隐式转换为“ Microsoft.Office.Interop.Excel.ColorFormat”

我找不到如何在两种格式之间进行转换。

在此处输入图片说明

Har*_*sad 5

一种选择是使用 ColorTranslator.ToOle

int oleColor = ColorTranslator.ToOle(Color.Red);
activeCell.Comment.Shape.Fill.BackColor.RGB = oleColor;
Run Code Online (Sandbox Code Playgroud)