Page 1 of 1

Tabstops

PostPosted: Mon Nov 25, 2013 9:01 pm
by Esanders323
Hi,

I'm trying to use tabstops for a line. The line has two words. I want the first word to be left aligned and for the other word to be on the other side on the right. I found CTTabStop but I'm slightly confused how I can use it.

For instance, here is what I want in my document.
WordOne WordTwo

Here is what I'm trying to do
Code: Select all
         ObjectFactory factory;
         factory = Context.getWmlObjectFactory();
         WordprocessingMLPackage wordMLPackage = null;
         CTTabStop ts = factory.createCTTabStop();
         ts.setPos();

How can I set the position of the tabstop?

Thanks!

Re: Tabstops

PostPosted: Mon Nov 25, 2013 9:34 pm
by jason
I suggest you create a docx (in Microsoft Word say) which looks as you describe, then save it, and upload it to the webapp (linked in the menu above).

With a bit of luck, that will generate the relevant code for you. If so, please post it here for the next person.

If you don't know how to create the sample docx, just let us know.

Re: Tabstops

PostPosted: Tue Nov 26, 2013 8:58 am
by Esanders323
I created the sample docx and uploaded it. I'm not really too sure what I'm doing with the webapp, but I got this. I'm not too sure what to look for
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml" PartName="/customXml/itemProps1.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" PartName="/docProps/app.xml"/>
<Override ContentType="application/vnd.openxmlformats-package.core-properties+xml" PartName="/docProps/core.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" PartName="/word/document.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" PartName="/word/fontTable.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml" PartName="/word/settings.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" PartName="/word/styles.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.theme+xml" PartName="/word/theme/theme1.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml" PartName="/word/webSettings.xml"/>
</Types>

Re: Tabstops

PostPosted: Tue Nov 26, 2013 12:20 pm
by jason
You need to click through to the main document part (word/document.xml), at which point you should see the XML representing your document, then click on the w:p containing your tabbed stuff

Re: Tabstops

PostPosted: Wed Nov 27, 2013 2:26 pm
by Esanders323
Worked great! Things for the help!

Code: Select all
import java.math.BigInteger;
import javax.xml.bind.JAXBElement;
import org.docx4j.wml.CTTabStop;
import org.docx4j.wml.P;
import org.docx4j.wml.PPr;
import org.docx4j.wml.R;
import org.docx4j.wml.R.Tab;
import org.docx4j.wml.Tabs;
import org.docx4j.wml.Text;


public class Foo {
public P createIt() {

org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();

P p = wmlObjectFactory.createP();
    // Create object for pPr
    PPr ppr = wmlObjectFactory.createPPr();
    p.setPPr(ppr);
        // Create object for tabs
        Tabs tabs = wmlObjectFactory.createTabs();
        ppr.setTabs(tabs);
            // Create object for tab
            CTTabStop tabstop = wmlObjectFactory.createCTTabStop();
            tabs.getTab().add( tabstop);
                tabstop.setVal(org.docx4j.wml.STTabJc.RIGHT);
                tabstop.setPos( BigInteger.valueOf( 10555) );
    // Create object for r
    R r = wmlObjectFactory.createR();
    p.getContent().add( r);
        // Create object for t (wrapped in JAXBElement)
        Text text = wmlObjectFactory.createText();
        JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
        r.getContent().add( textWrapped);
            text.setValue( "First");
    // Create object for r
    R r2 = wmlObjectFactory.createR();
    p.getContent().add( r2);
        // Create object for tab (wrapped in JAXBElement)
        R.Tab rtab = wmlObjectFactory.createRTab();
        JAXBElement<org.docx4j.wml.R.Tab> rtabWrapped = wmlObjectFactory.createRTab(rtab);
        r2.getContent().add( rtabWrapped);
    // Create object for r
    R r3 = wmlObjectFactory.createR();
    p.getContent().add( r3);
        // Create object for t (wrapped in JAXBElement)
        Text text2 = wmlObjectFactory.createText();
        JAXBElement<org.docx4j.wml.Text> textWrapped2 = wmlObjectFactory.createRT(text2);
        r3.getContent().add( textWrapped2);
            text2.setValue( "Second");

return p;
}
}