> For the complete documentation index, see [llms.txt](https://docs.tailent.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tailent.com/scripting-utility-classes/common-scripts-repository/c-scripts-repository/add-lov-in-excel.md).

# Add LOV in Excel

This script will require adding **using OfficeOpenXml;** to the namespaces section.

```csharp
using (ExcelPackage p = new ExcelPackage()) 
{
           ExcelWorksheet ws = excelDocument.getWorkSheet(1);
           
           for(int i = 1; i<20; i++)
           {
                      ws.Cells[i,2].Value="Default";
                      var unitmeasure = ws.DataValidations.AddListValidation("b"+i);
                      unitmeasure.Formula.Values.Add("Test");
                      unitmeasure.Formula.Values.Add("Test1");
                      unitmeasure.Formula.Values.Add("Default");			
           }
}
```

{% hint style="info" %}
The ExcelWorksheet variable has to be open using the “Open excel workbook” action before initializing the C# script, otherwise it will not be a valid reference to an Excel Workbook.

After the C# script action, use “Close excel workbook” to save the changes made.
{% endhint %}
