Page 1 of 1

Setting table row height

PostPosted: Thu Apr 07, 2011 2:58 am
by Squ36
Hi.

I'm currently using docx4j to create a Word document where the are a lot of tables (about 500 pages with only that...).
The problem is I can't seem to find where to set the row height.

In XML files, this is done with that :
Code: Select all
      <w:trPr>
        <w:trHeight w:val="480"/>
      </w:trPr>

right below the <w:t> opening tag.

But when I access the TrPr of my table, there is no function to set trHeight.

Anybody can help with that ?

Thanks a lot !

Re: Setting table row height

PostPosted: Thu Apr 07, 2011 10:55 pm
by jason
TrPr extends CTTrPrBase.


CTTrPrBase has:

Code: Select all
    public List<JAXBElement<?>> getCnfStyleOrDivIdOrGridBefore()


You can set the height by adding to that list the object returned by the following method in the ObjectFactory:

Code: Select all
    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link CTHeight }{@code >}}
     *
     */
    @XmlElementDecl(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "trHeight", scope = CTTrPrBase.class)
    public JAXBElement<CTHeight> createCTTrPrBaseTrHeight(CTHeight value) {
        return new JAXBElement<CTHeight>(_CTTrPrBaseTrHeight_QNAME, CTHeight.class, CTTrPrBase.class, value);
    }


To create a CTHeight object, use ObjectFactory's createCTHeight().

Re: Setting table row height

PostPosted: Fri Apr 08, 2011 2:38 am
by Squ36
Thank you very much !

Re: Setting table row height

PostPosted: Tue May 17, 2011 5:31 pm
by enmanuelr
Considering how easy and obvious everything else is (or at least has been so far), this was a bit of a shocker.

Can't it be as simple as adding a TrHeight object to TrPr? Just like the behavior of everything else?

In any case, thanks for the answer. Not working for me at the moment, but it's probably just my fault. Will keep trying.

Re: Setting table row height

PostPosted: Tue May 17, 2011 7:14 pm
by jason
enmanuelr wrote:Can't it be as simple as adding a TrHeight object to TrPr?


It pretty much is, except that you have to use ObjectFactory's createCTHeight() to create the CTHeight object.

If you are having problems, feel free to post your code.

Re: Setting table row height

PostPosted: Fri May 03, 2013 11:44 pm
by villanueva.ricardo
Thanks, I used this code:
Code: Select all
factory = Context.getWmlObjectFactory();
table = factory.createTbl();
         
TrPr trPr = new TrPr();
CTHeight ctHeight = new CTHeight();
ctHeight.setHRule(STHeightRule.EXACT);
JAXBElement<CTHeight> jaxbElement = factory.createCTTrPrBaseTrHeight(ctHeight);
trPr.getCnfStyleOrDivIdOrGridBefore().add(jaxbElement);


But finally I noticed that my problem (Rows height ) could be resolved deleting the space after paragraphs for each cell.

PPr pPr = factory.createPPr();
Spacing spacing = new Spacing();
spacing.setAfter(BigInteger.ZERO);
pPr.setSpacing(spacing);
paragraph.setPPr(pPr);
tableCell.getContent().add(paragraph);