[英]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.