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:
GemBox.Spreadsheet is a .NET component that enables you to read, write, convert, and print spreadsheet files (XLSX, XLS, XLSB, CSV, HTML, and ODS) from .NET applications.
With GemBox.Spreadsheet you get a fast and reliable component that's easy...
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.
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!