Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Apache POI Tab Stop word document

I have a word document that has lines like the following A name (aligned left) and a price (aligned all the way to the right) both on the same line. I believe this is done by a tab-stop in a word document. Here is an example, see the first line. enter image description here Is it possible for me to print out into a word document, a line like the first one? I checked around the documentation for apache POI but didn't see anything that allowed you to set a tab stop. However, I wasn't sure if there is another way to get the first line to look like that.

like image 888
Eric Avatar asked Nov 24 '25 15:11

Eric


1 Answers

I used this method to add tabs stops

public static void setTabStop(XWPFParagraph oParagraph, STTabJc.Enum oSTTabJc, BigInteger oPos)
{
    CTP oCTP = oParagraph.getCTP();
    CTPPr oPPr = oCTP.getPPr();
    if(oPPr == null)
    {
      oPPr = oCTP.addNewPPr();
    }

    CTTabs oTabs = oPPr.getTabs();
    if(oTabs == null)
    {
      oTabs = oPPr.addNewTabs();
    }

    CTTabStop oTabStop = oTabs.addNewTab();
    oTabStop.setVal(oSTTabJc);
    oTabStop.setPos(oPos);
}
like image 148
Patrick B Avatar answered Nov 26 '25 03:11

Patrick B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!