This project has moved. For the latest updates, please go here.

Table header every pages

Jan 17, 2011 at 6:47 AM

Hi,

i have to repeat every pages a table header columns.

how can i do it programmatically?

thanks

Coordinator
Jan 17, 2011 at 8:49 AM
Hi acquleo,

"if your question is how do Icreate a Header and have it displayed on every page of my document". Please see the following blogpost http://cathalscorner.blogspot.com/2010/06/docx-version-10010.html

If that is not your question, I have miss understood, please try re-phrasing your question.

Happy Coding,
Cathal
Jan 17, 2011 at 9:44 AM

What i mean is to create a table that repeated the first row every pages if the table filled more then one page.

I found a workaround, I create a document with word 2007, i made a table with only one row configured with "Repeat as header row at the top of each page".

Then i filled the other rows with docx library.

Thank you very much

Leonardo

Da: coffeycathal [email removed]
Inviato: Monday, January 17, 2011 10:49 AM
A: leonardo.acquisti@tetsistemi.com
Oggetto: Re: Table header every pages [DocX:242037]

From: coffeycathal

Hi acquleo,

"if your question is how do Icreate a Header and have it displayed on every page of my document". Please see the following blogpost http://cathalscorner.blogspot.com/2010/06/docx-version-10010.html

If that is not your question, I have miss understood, please try re-phrasing your question.

Happy Coding,

Cathal

May 24, 2011 at 4:39 PM

Hi acquleo,

Did you solve this problem? i´m trying to do the same thing.

Rodrigo

 

 

May 25, 2011 at 6:45 AM

Rodrigo,

I don’t remember exactly how I solve it… because we have choice to generate ODT instead.

I seem to remember that I have entered data into an existing docx files on a pre-created table.

Leonardo

Da: rodrigomacedo [email removed]
Inviato: Tuesday, May 24, 2011 6:40 PM
A: leonardo.acquisti@tetsistemi.com
Oggetto: Re: Table header every pages [DocX:242037]

From: rodrigomacedo

Hi acquleo,

Did you solve this problem? i´m trying to do the same thing.

Rodrigo

Jun 3, 2011 at 1:45 PM

Acquileo, thanks for reply.

a friend who works with me solved the problem, he created a document in word that had a table like that. Then he created a doc via code without repeating the title.

Comparing the two xml files (docx is xml), it was easy to see which tags were missing. 

Downloading the source code of docx.dll was possible to see how to create tables with header repeating

Rodrigo
 

Oct 6, 2011 at 9:03 AM

I solved this by injecting an XElement in the table xml between th AddTable and the InsertTable method calls. It turns out there is only an empty tag needed in the last row to be repeated on each page.

 

private void SetRepeatingHeaderRow(Novacode.Table table)
        {
            var headerRow = table.Rows.FirstOrDefault();
            if (headerRow == null) return;
            var ns = XNamespace.Get("http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            var xml = headerRow.Xml;
            xml.Add(new XElement(ns+"trPr",new XElement(ns+"tblHeader")));
        }


        
    
Jan 9, 2014 at 8:31 PM
this is released in latest stable version ?
Thanks.
Developer
Jan 9, 2014 at 8:45 PM
I would suggest using the source and compile it yourselfs. There's like milion fixes.
Feb 12, 2016 at 9:27 AM
Use the following code:

Table t;
t.Rows.FirstOrDefault().TableHeader = true; //This will make the first row of the table a headerRow

//Example code of my header row
for (int i = 0; i < t.ColumnsCount; i++)
        {
            t.Rows[0].Cells[i].TextDirection = TextDirection.btLr;
            t.Rows[0].Cells[i].Paragraphs.First().Append("some text");
        }