i am creating an excel ribbon, where there is a dropdown list that should be filled up with Values from an excel file.
it should check through the first column and when it meets the string X then it should add to the dropdown the value of the cell in the same row but in the third column
there is an error in the last line of code with converstion to string not possible
private void AutoFill_Load(object sender, RibbonUIEventArgs e)
{
DropList.Items.Clear();
using (ExcelPackage package = new ExcelPackage(new FileInfo(path1)))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets["XYZ"];
List<string> uniqueValues = new List<string>();
for (int row = 1; row <= worksheet.Dimension.End.Row; row++)
{
string valueA = worksheet.Cells[row, 1].Value?.ToString();
if (valueA == "X")
{
string valueC = worksheet.Cells[row, 3].Value?.ToString();
if (!uniqueValues.Contains(valueC))
{
uniqueValues.Add(valueC);
}
}
}
DropList.Items.Add(uniqueValues.ToArray());
}
}