officefileapi-402919-word-processing-document-api-examples-tables-how-to-repeat-table-rows-as-header.md
Word Processing Document API offers two options to control the appearance of large tables that span across multiple pages:
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.Docx);
}
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();
}
Using wordProcessor As New RichEditDocumentServer()
AdjustTableRows(wordProcessor.Document)
wordProcessor.SaveDocument("DocumentWithTables.docx",
DocumentFormat.Docx)
End Using
private static void AdjustTableRows(Document document)
Dim table As 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()
End Sub