Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a header in a table for each new page with OpenXml Wordprocessing

I am trying to create a table with a header. I want this header to be repeated for each new page that the table takes. How can I do this in C# and OpenXml Wordprocessing?

DocumentFormat.OpenXml.Packaging.WordprocessingDocument internalDoc = 
DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(stream, true);

var tables = wordDoc.MainDocumentPart.Document.Descendants<SdtBlock>().Where
( r => r.SdtProperties.GetFirstChild<Tag>().Val.Value.StartsWith(DATA_TABLE_TAG));

Table table = tables.Descendants<Table>().Single();
//Here can I set some property to repeat the header of the table? 
like image 450
RRR Avatar asked Sep 07 '11 20:09

RRR


1 Answers

As Chris said, an instance of the TableHeader class is what you need. It needs to be appended to the header row's TableRowProperties:

var row = table.GetFirstChild<TableRow>();

if (row.TableRowProperties == null)
    row.TableRowProperties = new TableRowProperties();

row.TableRowProperties.AppendChild(new TableHeader());
like image 100
Michael Csikos Avatar answered Nov 14 '22 22:11

Michael Csikos