excel drop down list code example

Example 1: html create drop down list

<html>
 <head>
   <title>Selection Inputs</title>
 </head>
 <body>
   <form>
     <label for="selector"> <!-- Can add label if want -->
       <p>A "select" element allows users to input from a selection:</p>
       <select id="selector"> <!-- Use "select" to create object -->
         <option>Option 1</option> <!-- Add all applicable options -->
         <option>Option 2</option>
         <option selected>Option 3</option> <!-- add selected to change default from first option -->
         <optgroup label="Group"> <!-- To create nested options for categories use "optgroup" -->
           <option>Option 4</option>
           <option>Option 5</option>
       </select>
     </label>
   </form>
 </body>
</html>

Example 2: excel sheet with drop down list

var options = new List<string>{"Option1","Option2","Option3"};
var validOptions = $"\"{String.Join(",", options)}\"";
ws.Cell(1,1).DataValidation.List(validOptions, true);

//validOptions contains :
"Option1,Option2,Option3"

//Your own code should change to :

.List("\"one,two,three\"", true);

Tags:

Html Example