Aspose.Words

Specifying Rows to Repeat on Subsequent Pages as Header Rows

A table can specify certain starting rows of a table to be used as header rows. This means if the table spans over many pages, these rows will be repeated at the top of the table for each page.

In Microsoft Word this option is found under Table Properties as “Repeat row as header on subsequent pages”. Using this option you can choose to repeat only a single row or many rows in a table.

In the case of a single header row it must be the first row in the table. In addition when multiple header rows are used then the header row each of these rows must be consecutive and these rows must be on one page.

Note that heading rows do not work in nested tables. That is, if you have a table within another table then this setting will have no effect. This is a limitation of Microsoft Word which does not allow this and not of Aspose.Words.

In Aspose.Words you can apply this setting by using the RowFormat.HeadingFormat property.

Example InsertTableWithHeadingFormat

Shows how to build a table which include heading rows that repeat on subsequent pages.

[Java]

 

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

 

Table table = builder.startTable();

builder.getRowFormat().setHeadingFormat(true);

builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

builder.getCellFormat().setWidth(100);

builder.insertCell();

builder.writeln("Heading row 1");

builder.endRow();

builder.insertCell();

builder.writeln("Heading row 2");

builder.endRow();

 

builder.getCellFormat().setWidth(50);

builder.getParagraphFormat().clearFormatting();

 

// Insert some content so the table is long enough to continue onto the next page.

for (int i = 0; i < 50; i++)

{

    builder.insertCell();

    builder.getRowFormat().setHeadingFormat(false);

    builder.write("Column 1 Text");

    builder.insertCell();

    builder.write("Column 2 Text");

    builder.endRow();

}

 

doc.save(getMyDir() + "Table.HeadingRow Out.doc");