EasyXLS

How to create drop down list in Excel

EasyXLS™ library allows you to create drop down lists in Excel file. A drop down list is a data validation that permits entering only values from the list in the cell.

Source code sample

The below example shows how to export an Excel file with a drop down list with valid values from a named range.

C#.NET
VB.NET
C++
Java
PHP
ASP
VB6
VBS
Coldfusion
Python

// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);

// Set sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");

...

// Create named range
xlsSecondTab.easy_addName("Range", "=Second tab!$A$1:$A$4");

// Add data validation as drop down list type
ExcelWorksheet xlsFirstTab = (ExcelWorksheet)workbook.easy_getSheetAt(0);
xlsFirstTab.easy_addDataValidator("A1:A10", DataValidator.VALIDATE_LIST, 
        DataValidator.OPERATOR_EQUAL_TO, "=Range", "");
 
// Create Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel drop down list.xlsx");

     Click here to see Continuous Code Listing

The screen shot provides an example of an Excel file with a drop down list.

Excel drop down list

 
 

Available for: Professional, Excel Writer, Excel Reader
Go to top

EasyXLS Excel libraries:

.NET
.NET Excel Library
full .NET version to import, export or convert Excel files
.NET Excel Writer
.NET version to create and export Excel files
COM+ Excel Library
full COM+ version to import, export or convert Excel files
COM+ Excel Writer
COM+ version to create and export Excel files
-
Java
Java Excel Library
full Java version to import, export or convert Excel files
Java Excel Writer
Java version to create and export Excel files
Download EasyXLS™ Excel Library for .NET and Java

File formats:

Office 365
MS Excel 2021 - 2025
MS Excel 2007 - 2019
MS Excel 97 - 2003
XLSXXLSMXLSBXLS
XMLHTMLCSVTXT