[英]add combobox to excel
I want to export some data as excel in my project.我想在我的项目中将一些数据导出为 excel。 I prepared a structure for this.我为此准备了一个结构。 I want to have comboboxes in some columns in this structure.我想在这个结构的某些列中有组合框。
I found the example below, but this example doesn't work for me.我找到了下面的例子,但这个例子对我不起作用。 Normally he should add data one after the other, but he perceives them as a text and adds.通常他应该一个接一个地添加数据,但他将它们视为文本并添加。
It does not add the addition as a separate element.它不会将添加添加为单独的元素。 It adds "Item 1, Item 2, Item 3" into the combobox. How can I solve this problem.它在 combobox 中添加了“项目 1、项目 2、项目 3”。我该如何解决这个问题。
Microsoft.Office.Interop.Excel version 15.0.0.0 Microsoft.Office.Interop.Excel 版本 15.0.0.0
I used Office 365.我用的是 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";
Concatenating data with "," does not work.用“,”连接数据不起作用。 Instead of ";"代替 ”;” Combining with fixed the problem.结合修复问题。
var items = new List<string>() { "Item 1", "Item 2", "Item 3" };
var formattedItems = string.Join(";", items.ToArray());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.