使用C#和Excel.Interop更改下拉列表的背景颜色

时间:2019-06-20 13:59:11

标签: c# excel office-interop excel-interop

我想对下拉列表中的元素使用不同的背景色。我生成了如下的下拉列表:

var list = new System.Collections.Generic.List<string>();
list.Add("okay");
list.Add("delete");
list.Add("else (Comment)");
var myDDL = string.Join(",", list.ToArray());
var celldd = (Excel.Range)mysheet.Cells[row_counter, 10];
celldd.Validation.Delete();

try
{
    int type = celldd.Validation.Type;
    Console.WriteLine("The validation have already been added");
 }
 catch (System.Runtime.InteropServices.COMException)
 {
    celldd.Validation.Add(
          Excel.XlDVType.xlValidateList,
          Excel.XlDVAlertStyle.xlValidAlertInformation,
          Excel.XlFormatConditionOperator.xlBetween,
          myDDL, misValue);
 }
 celldd.Validation.InCellDropdown = true;
 celldd.Validation.IgnoreBlank = true;
 celldd.Locked = false;
 celldd.Value2 = "Choose";
 celldd.Interior.Color = ColorTranslator.ToOle(Color.Plum);

这可能吗?到目前为止,只有默认值具有背景色。

0 个答案:

没有答案