updating column after creation to have dropdown of options

19 Views Asked by At

I have this method here:

        using (XLWorkbook workbook = new XLWorkbook())
        {
            // Export Rates worksheet
           ExportToWorksheet(workbook, "Rates", rateItems, fixedRateProperties, flexibleRateProperties);

            var ratesWorksheet = workbook.Worksheet("Rates");

            var range = ratesWorksheet.RangeUsed();
            var table = range.AsTable();
            var cell = table.HeadersRow().CellsUsed(c => c.Value.ToString() == "Included").FirstOrDefault();
            var columnLetter = cell.WorksheetColumn().ColumnLetter();

            var column = table.Column(columnLetter);
             ratesWorksheet.Column(columnLetter).CreateDataValidation().List("Yes, No", true);

            // Save the workbook to the specified file path
            workbook.SaveAs(filePath);
        }

the ExportToWorksheet method creates the worksheet and then what I want to do is go through the worksheet, find the column Included and then make all of the rows underneath it have a dropdown where the user can select either yes or no with the default being no.

This will run with no errors but when I open the excel sheet, it comes up saying "We found a problem with some content in 'Example.xlsx' Do you want us to try recover as much as we can? If you trust the source of the workbook, click yes."

And when I do and look to see what has been done to fix it I get:

<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error137120_06.xml</logFileName>
<summary>Errors were detected in file 'C:\Data\Example.xlsx'</summary>
<removedFeatures>
<removedFeature>Removed Feature: Data validation from /xl/worksheets/sheet1.xml part</removedFeature>
</removedFeatures>

So I'm wondering where it is I'm going wrong? why can't I add the data validation like this?

0

There are 0 best solutions below