Open valimaties opened 2 years ago
Hi,
If you want to add a table in an header and each pages contains this table in the header, here's how:
var doc = DocX.Create("test.docx");
doc.AddHeaders();
var table = doc.Headers.Odd.InsertTable( 1, 2 );
table.Rows[ 0 ].Cells[ 0 ].Paragraphs[ 0 ].Append( "First" );
table.Rows[ 0 ].Cells[ 1 ].Paragraphs[ 0 ].Append( "Second" );
doc.InsertParagraph().InsertPageBreakAfterSelf();
doc.InsertParagraph().InsertPageBreakAfterSelf();
doc.InsertParagraph().InsertPageBreakAfterSelf();
doc.Save();
But if you have a big table, which splits on many pages and want to display the Table header on each page, you can use: table.Rows[ 0 ].TableHeader = true; var doc = DocX.Create("test.docx");
var table = doc.InsertTable( 100, 2 );
table.Rows[ 0 ].Cells[ 0 ].Paragraphs[ 0 ].Append( "HEADER_1" );
table.Rows[ 0 ].Cells[ 1 ].Paragraphs[ 0 ].Append( "HEADER_2" );
table.Rows[ 0 ].TableHeader = true;
for( int i = 1; i < 100; ++i )
{
for( int j = 0; j < 2; ++j )
{
table.Rows[ i ].Cells[ j ].Paragraphs[ 0 ].Append( i.ToString() );
}
}
doc.Save();
Thank you. The table is big I don't know how many rows it has. So the second approach helps me. Right now I'm in a small vacantion, but I will try it when I came back to home. Thanks again.
Hi. Can be made such thing? To insert a table which repeats its header on each page? Thanks