How to: Repeat Table Rows as Header
Word Processing Document API offers two options to control the appearance of large tables that span across multiple pages:
- TableRow.RepeatAsHeaderRow - Repeats a header row at the top of each page;
- TableRow.BreakAcrossPages - Specifies whether the row can be split when the table expands to another page.
The code sample below toggles Repeat row as header and Break row across pages options in code:
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
AdjustTableRows(wordProcessor.Document);
wordProcessor.SaveDocument("DocumentWithTables.docx",
DocumentFormat.OpenXml);
}
private static void AdjustTableRows(Document document)
{
Table table = document.Tables[0];
table.BeginUpdate();
//Repeat first three rows as header:
table.Rows[0].RepeatAsHeaderRow = true;
table.Rows[1].RepeatAsHeaderRow = true;
table.Rows[2].RepeatAsHeaderRow = true;
//Break last row across pages:
table.LastRow.BreakAcrossPages = true;
table.EndUpdate();
}