This project has moved and is read-only. For the latest updates, please go here.

Changing table column header texts

Mar 28, 2014 at 2:09 PM
Edited Mar 28, 2014 at 2:09 PM

thanks for the effort you've put into ClosedXML.

However, I'm struggling with tables on sheets. In the code (please see below, VS2012, .NET 4.0, ClosedXML I load an XLSX file which only contains a table with headers on a sheet. If I then change a column header text via the cell's Value property or SetValue method, Excel 2013 complains about invalid data in the saved XLSX file when opening it. What is the suggested way to change a table column's header text? Does it matter whether the table's header cell is accessed via the worksheet's Cell(...) method or via the table object's Cell(...) method?
I tried the example from and it does work but unfortunately there's a template XLSX file with an existing table I need to alter and populate with data. I also tried to change the header text using the output file of the linked example as template. The Open XML 2.0 SDK Productivity Tools validation only points out four invalid margins in the XLSX file. A diff on both XLSX file contents does not reveal anything unexpected.

Any help is appreciated. Thanks a lot in advance!

Kind regards,

Code excerpt:
using (XLWorkbook workbook = new XLWorkbook(@"template.xlsx"))
    // Access sheet and table by indices because this example only contains one sheet and one table.
    IXLWorksheet sheet = workbook.Worksheet(1);
    IXLTable table = sheet.Table(0);
    // Change first column header text.
    table.Cell(1, 1).Value = "Name";
May 27, 2014 at 1:23 PM
Tried working with the table fields. While I was debugging I noticed that the fieldnames still contains column28 as the name of the last field even though I set the name of the field to Card by this line .
tbl.Field(tbl.Fields.Last.Index).Name = ScheduleFields.HasCard
May 27, 2014 at 2:42 PM
You're right, it should change the field name on the sheet. I just committed a fix for it. Pick up the latest source code.