Page 1 of 1

Repeat table header on every page.

PostPosted: Thu May 31, 2018 10:01 pm
by Venkatesh G
Is it possible to repeat the table header on each page in java code.
If it is possible please me help me.
Thank you in advance.

Re: Repeat table header on every page.

PostPosted: Sat Jun 02, 2018 10:34 am
by jason
Sure, you can do in docx4j what you can do in Word.

In Word, its table properties > row > repeat as header at the top of each page

Using the Docx4j Helper Word AddIn, you can see you need the following on your row (tr):

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
            <w:tr >
                <w:trPr>
                    <w:tblHeader/>
                </w:trPr>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


The AddIn generates the following code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                // Create object for trPr
                TrPr trpr = wmlObjectFactory.createTrPr();
                tr.setTrPr(trpr);
                    // Create object for tblHeader (wrapped in JAXBElement)
                    BooleanDefaultTrue booleandefaulttrue = wmlObjectFactory.createBooleanDefaultTrue();
                    JAXBElement<org.docx4j.wml.BooleanDefaultTrue> booleandefaulttrueWrapped = wmlObjectFactory.createCTTrPrBaseTblHeader(booleandefaulttrue);
                    trpr.getCnfStyleOrDivIdOrGridBefore().add( booleandefaulttrueWrapped);
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4

Re: Repeat table header on every page.

PostPosted: Mon Jun 04, 2018 11:22 pm
by Venkatesh G
thank you for the response.

As per the code it is working for one document, for the other document it is not working

Previously i written this code.

Tbl tempTable = getTemplateTable(tables, placeholders[0]);
String strTrPr = "<w:trPr xmlns:w=\"schemas.openxmlformats.org/wordprocessingml/2006/main\">" + "<w:tblHeader />" + "</w:trPr>";
List<Object> rows = getAllElementFromObject(tempTable, Tr.class);
Tr templateRow = (Tr) rows.get(0);
templateRow.setTrPr((TrPr)XmlUtils.unmarshalString(strTrPr,Context.jc, TrPr.class));

and i used the code as you mentioned before also, but not working for the attached document.

I didn't get what is the problem exactly. can you please check it once.

thank you in advance.