Page 1 of 1

JcEnumeration.BOTH or JcEnumeration.DISTRIBUTED not working

PostPosted: Sat Dec 15, 2012 4:35 am
by garyg
Hi,

I have setup some code to perform some formatting. I can use JcEnumeration.RIGHT, LEFT, CENTER and it applies the w:jc tag appropriately. But when I use BOTH or DISTRIBUTED nothing gets set in the document xml for the w:jc tag.

I notice that Word uses "BOTH" for justify alignment. Either way (BOTH or DISTRIBUTED) my code does not work. Here is an example of how I set CENTER which works and then the same approach for BOTH or DISTRIBUTED:

Code: Select all

//This works
Jc alignment = new Jc();
alignment.setVal(JcEnumeration.RIGHT);
//paragraph is an instance of P 
paragraph.getPPr().setJc(alignment);


//This does not work
Jc alignment = new Jc();
alignment.setVal(JcEnumeration.BOTH); //Have used DISTRIBUTED also
paragraph.getPPr().setJc(alignment);


As I said, the second version no w:jc tag gets set in the document

Thanks.

Re: JcEnumeration.BOTH or JcEnumeration.DISTRIBUTED not work

PostPosted: Sat Dec 15, 2012 7:17 am
by garyg
I ended up resolving the problem. I had not posted all of the code, clearly, but the problem ended up being a brain-lock on my part. I was applying the BOTH to a new paragraph, but forgot to put the new paragraph into the document.

Thanks if you had looked into this though!

Re: JcEnumeration.BOTH or JcEnumeration.DISTRIBUTED not work

PostPosted: Sat Dec 15, 2012 9:17 pm
by jason
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                Jc alignment = new Jc();
                alignment.setVal(JcEnumeration.BOTH); //Have used DISTRIBUTED also
            org.docx4j.wml.PPr ppr1 = factory.createPPr();         
            p.setPPr( ppr1 );
                p.getPPr().setJc(alignment);   
               
                System.out.println(XmlUtils.marshaltoString(p, false));
 
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


works for me.