简体   繁体   中英

How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color

I'm developing a vsto addin for Excel, and I'm trying to change the color to the comments in Excel.

This is the code that I have:

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

The exception I'm getting is:

Cannot implicitly convert type 'System.Drawing.Color' to 'Microsoft.Office.Interop.Excel.ColorFormat'

I cannot find how to make a conversion between the two formats.

在此处输入图片说明

One option is to use ColorTranslator.ToOle

int oleColor = ColorTranslator.ToOle(Color.Red);
activeCell.Comment.Shape.Fill.BackColor.RGB = oleColor;

Try this:

activeCell.Comment.Shape.Fill.BackColor = XlRgbColor.rgbRed;

Or this(EDIT: False):

activeCell.Comment.Shape.Fill.BackColor.RGB =  Color.FromRgb(255,0,0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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