Add dropdown list in the Excel sheet using C#

前端 未结 1 1424
我在风中等你
我在风中等你 2021-01-03 12:21

I am filling the Excel cells as row and column using C# in my entire project as given below. Now there is a new requirement to add a dropdownlist in the particular cell.

1条回答
  •  借酒劲吻你
    2021-01-03 13:10

    First make a list for dropdown

            var list = new System.Collections.Generic.List();
            list.Add("Charlie");
            list.Add("Delta");
            list.Add("Echo");
            var flatList = string.Join(",", list.ToArray());
    

    then add this list as dropdown in the particular cell as below

    var cell = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[row, 8];
                cell.Validation.Delete();
                cell.Validation.Add(
                   XlDVType.xlValidateList,
                   XlDVAlertStyle.xlValidAlertInformation,
                   XlFormatConditionOperator.xlBetween,
                   flatList,
                   Type.Missing);
    
                cell.Validation.IgnoreBlank = true;
                cell.Validation.InCellDropdown = true;
    

    0 讨论(0)
提交回复
热议问题