Excel Table created by GemBox must be repaired before Excel can open the file

Version 49.0.1623

Adding a table with these lines, causes an error when opening the excel file generated (attached). Are the additional details I should define at this time?

   worksheet.Tables.Add("dataTable", "A1:" + worksheet.Columns[CountA + 3] + (CountB+ 1), true);
   worksheet.Tables["dataTable"].BuiltInStyle = BuiltInTableStyleName.TableStyleMedium2;
   worksheet.Tables["dataTable"].StyleOptions = TableStyleOptions.BandedRows;



Hi,

Please try again with the current latest version of GemBox.Spreadsheet:

Does this solve your issue?

Regards,
Mario

Thank you Mario!

Unfortuatnely I still cannot get approval for an updated license.

The error occurs when I Add or InsertAt a column to an existing table.

Can you think of any work around for either of these cases?

Can you send us that XLSX so we can investigate it?
I presume that the problem could be with the column’s name.

Thanks Mario, Here are the outputs from having GemBox adding the table to an existing template file as well has having it add a column to an existing table in the template… it may not be the same error in both cases.

https://www.dropbox.com/scl/fo/g9ma3yxzadui4u6ol83rz/AFEpq01X1qmXbYD275ueUWM?rlkey=lom0um8itzu7ehgrzqbe5wbcu&st=8asse4ya&dl=0

The problem occurs because the last two TableColumn have the same name:

var workbook = ExcelFile.Load("January 2025 Results - Table Column Added by Gembox.xlsx");
var worksheet = workbook.Worksheets.ActiveWorksheet;
var table = worksheet.Tables[0];

foreach (var column in table.Columns)
    Console.WriteLine(column.Name);

To resolve this with your older version of GemBox.Spreadsheet, you’ll need to make sure that the names are unique, for example:

var uniqueNames = new HashSet<string>();
foreach (var column in table.Columns)
{
    string originalName = column.Name;
    string uniqueName = originalName;
    int counter = 0;

    while (uniqueNames.Contains(uniqueName))
        uniqueName = originalName + ++counter;

    if (originalName != uniqueName)
        column.Name = uniqueName;

    uniqueNames.Add(uniqueName);
}

I hope this helps.

Regards,
Mario

Much appredicated Mario! I’ll let you know how it goes.
Thank you!