如何从C#中的System.Drawing.Color转换为Excel.ColorFormat? 更改评论颜色
我正在开发一个Excel的vsto插件,我试图将颜色更改为Excel中的注释。
这是我有的代码:
Excel.Range activeCell = _application.ActiveCell; activeCell.AddComment("some text")); activeCell.Comment.Shape.Fill.BackColor = Color.Red;
我得到的例外是:
不能将types“System.Drawing.Color”隐式转换为“Microsoft.Office.Interop.Excel.ColorFormat”
我找不到如何在两种格式之间进行转换。
一个select是使用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);