【问题标题】:add combobox to excel将组合框添加到 Excel
【发布时间】:2022-04-13 15:56:48
【问题描述】:

我想在我的项目中将一些数据导出为 excel。我为此准备了一个结构。我想在此结构的某些列中包含组合框。

我找到了下面的例子,但这个例子对我不起作用。通常他应该一个接一个地添加数据,但他将它们视为文本并添加。

Example

它不会将添加添加为单独的元素。它将“第 1 项、第 2 项、第 3 项”添加到组合框中。我该如何解决这个问题。

Microsoft.Office.Interop.Excel 版本 15.0.0.0

我使用的是 Office 365。

var items = new List<string>() { "Item 1", "Item 2", "Item 3" };
        var formattedItems = string.Join(",", items.ToArray());

        var dropDownRange = sunWorksheet.Range["J2"].EntireColumn;
        dropDownRange.Validation.Delete();
        dropDownRange.Validation.Add(Excel.XlDVType.xlValidateList,
            Excel.XlDVAlertStyle.xlValidAlertInformation,
            Excel.XlFormatConditionOperator.xlBetween,
            formattedItems,
            Type.Missing);

        dropDownRange.Value = "Item 2";

【问题讨论】:

    标签: excel combobox


    【解决方案1】:

    用“,”连接数据不起作用。代替 ”;”结合解决问题。

    var items = new List<string>() { "Item 1", "Item 2", "Item 3" };
            var formattedItems = string.Join(";", items.ToArray());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-04
      • 2012-03-04
      • 2014-09-11
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多