How to set multiple select dropdown in Excel using C# DocumentFormat.OpenXml library?

Lalith 20 Reputation points
2025-07-11T04:20:49.1966667+00:00

How to set a multiple select dropdown in Excel using C#? I was able to generate Single Select Dropdown, I want the Column A to be multi select dropdown, Is it even possible to have a multi select drop down in Excel?

Existing Code:

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

byte[] data;

using (var memoryStream = new MemoryStream())
{
    using (SpreadsheetDocument document = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook))
    {
        WorkbookPart workbookPart = document.AddWorkbookPart();
        workbookPart.Workbook = new Workbook();
        WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
        SheetData sheetData = new SheetData();
        Row headerRow = new Row();
        headerRow.Append(
            CreateTextCell("A", 1, "Multi-Select Drop-Down"),
            CreateTextCell("B", 1, "Single-Select Drop-Down")
        );
        sheetData.Append(headerRow);
        worksheetPart.Worksheet = new Worksheet(sheetData);
        Sheets sheets = document.WorkbookPart!.Workbook.AppendChild(new Sheets());
        Sheet sheet = new Sheet()
        {
            Id = document.WorkbookPart?.GetIdOfPart(worksheetPart),
            SheetId = 1,
            Name = "DropDownExample"
        };
        sheets.Append(sheet);
        AddSingleSelectDropDown(worksheetPart);
        workbookPart.Workbook.Save();
    }

    memoryStream.Seek(0, SeekOrigin.Begin);

    data = memoryStream.ToArray();
}

File.WriteAllBytes("test.xlsx", data);

static void AddSingleSelectDropDown(WorksheetPart worksheetPart)
{
    DataValidations dataValidations = new DataValidations();
    string listValues = "\"Option1,Option2,Option3\"";
    DataValidation dataValidation = new DataValidation
    {
        Type = DataValidationValues.List,
        AllowBlank = true,
        ShowInputMessage = true,
        ShowErrorMessage = true,
        Formula1 = new Formula1(listValues),
        SequenceOfReferences = new ListValue<StringValue> { InnerText = $"B2:B1048576" }
    };
    dataValidations.Append(dataValidation);
    worksheetPart.Worksheet.Append(dataValidations);
}

static Cell CreateTextCell(string columnName, uint rowIndex, string cellValue)
{
    Cell cell = new Cell()
    {
        DataType = CellValues.Date,
        CellReference = columnName + rowIndex
    };
    cell.CellValue = new CellValue(cellValue);
    return cell;
}
Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

Answer accepted by question author
Anonymous
2025-07-11T14:55:49.8933333+00:00

Dear @Lalith,

Thank you so much for contacting Microsoft Q&A Forum. 

Based on your description, you're correct that using the DocumentFormat.OpenXml library, you can create single-select dropdowns in Excel via data validation lists. However, multi-select dropdowns are not natively supported in Excel through data validation or OpenXML. So, here are more information for you: 

What’s possible with OpenXML:  

  • Single-select dropdowns using DataValidationValues.List (as you’ve already implemented). 
  • These dropdowns allow the user to pick one value only from a predefined list. 

What’s not possible natively: 

  • Multi-select dropdowns (i.e., selecting multiple values from a dropdown and having them appear in a single cell) are not supported by Excel’s built-in data validation. 
  • OpenXML cannot implement VBA macros or event-driven logic directly. 

Reference: Create a drop-down list - Microsoft Support 

Therefore, if you must have multi-select behavior, I have several ideas that you can check if they work: 

  • Add a note in the Excel file explaining that users can manually select multiple values by typing them in, separated by commas. 
  • Or embed a VBA macro using another tool to simulate multi-select behavior. This macro would: 
    • Trigger on cell selection or change. 
      • Append selected values to the cell, separated by commas. 

I hope this information can help you to find a suitable way to finish it and please correct me if I misunderstand your concern. 

Wish you a pleasant day!


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

User's image

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Newest

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.