I am trying to create a table with a header. I want this header to be repeated for each new page that the table takes. How can I do this in C# and OpenXml Wordprocessing?
DocumentFormat.OpenXml.Packaging.WordprocessingDocument internalDoc =
DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(stream, true);
var tables = wordDoc.MainDocumentPart.Document.Descendants<SdtBlock>().Where
( r => r.SdtProperties.GetFirstChild<Tag>().Val.Value.StartsWith(DATA_TABLE_TAG));
Table table = tables.Descendants<Table>().Single();
//Here can I set some property to repeat the header of the table?
As Chris said, an instance of the TableHeader class is what you need. It needs to be appended to the header row's TableRowProperties:
var row = table.GetFirstChild<TableRow>();
if (row.TableRowProperties == null)
row.TableRowProperties = new TableRowProperties();
row.TableRowProperties.AppendChild(new TableHeader());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With