Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Changing table column header texts

$
0
0
Hello,

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 0.69.1.0) 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 https://closedxml.codeplex.com/discussions/406341 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,
Kristian


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);
    workbook.SaveAs(@"resultOriginal.xlsx");
    // Change first column header text.
    table.Cell(1, 1).Value = "Name";
    workbook.SaveAs(@"result.xlsx");
}

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>