How to determine the big table if more than one page- and automatically add header in table on page 2

I have the big table, has been divided into 2 pages, how to determine if more than one page, and automatically add header in front of the table on page 2 in word document?

Hi Li,

Thanks for your inquiry. You can achieve this by implementing the following workflow:

  • Get reference to the first paragraph of first cell of first row of Table.
  • Find its page number using LayoutCollector.GetStartPageIndex method
  • Get reference to the last paragraph of last cell in last row of Table.
  • Find its page number using LayoutCollector.GetEndPageIndex method
  • Compare two page numbers to determine whether table spans more than one page or not

Secondly, you can set RowFormat.HeadingFormat property to true if the row is repeated as a table heading on every page when the table spans more than one page.

I hop, this helps.

Best regards,

thanks,most has been solved, but the shortage is the result of similar to the attachment multi header processing is single

Hi Li,

Thanks for your inquiry. Unfortunately, your question isn’t clear enough therefore we request you to please elaborate your inquiry further and share complete source code you’re getting problems with. This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

Best regards,

my source file is 11.docx,my target file is 11target.docx

Hi Li,

Thanks for your inquiry. I checked your code and it produces expected output (similar to one shown in 11target.docx). In case you have further inquires or need any help, please let us know.

Best regards,

output file(11t.docx) the first row header added automatically, but didn’t add the second row header.

Hi Li,

Thanks for your inquiry. You can simply set HeadingFormat flag to true for the second row as follows:

Document doc = new Document(MyDir + @"11t.docx");
Table tab = doc.FirstSection.Body.Tables[0];
tab.Rows[0].RowFormat.HeadingFormat = true;
tab.Rows[1].RowFormat.HeadingFormat = true;
doc.Save(MyDir + @"out.docx");

I hope, this helps.

Best regards,

Thanks,but your code can only be header rows are fixed.There are a lot of tables, and the table header rows are random, how to write the code to automatically adapt to changing conditions different row of header in table?

Hi Li,

Thanks for your inquiry. Well, I think if you could place an empty bookmark at the last row which you want to appear as header row, then you can iterate through rows collection and dynamically make rows as header rows until you find a row containing that empty bookmark. I hope, this helps.

Best regards,