Reputation: 564
I want to export some data as excel in my project. 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.
Microsoft.Office.Interop.Excel version 15.0.0.0
I used 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";
Upvotes: 3
Views: 328
Reputation: 564
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());
Upvotes: 1