Hi All I am trying to create a dropdown list for a column in my excel using ClosedXML library. I am able to create it successfully using the below code.
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt);
wb.Worksheets.Add(dt2);
var worksheet2 = wb.Worksheet(2);
//wb.Worksheet(1).Column(11).SetDataValidation().List("one,two,three", true); This does not work fine
wb.Worksheet(1).Column(11).SetDataValidation().List(worksheet2.Range("A2:A12"), true);// Works fine
wb.Worksheet(1).Column(11).SetDataValidation().IgnoreBlanks = true;
wb.Worksheet(1).Column(11).SetDataValidation().InCellDropdown = true;
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
wb.SaveAs(targetFile);
}
But I want to do the same thing with another overloaded method of List in SetDataValidation() but that is creating the excel but when I am trying to open it, it says its corrupted. Could you please help me understand why the other overloaded method is not working.