简体   繁体   中英

Java apache POI - How do I do, in word using poi, every page has borders?

I need to make borders on every word pages like on paragraphs:

XWPFParagraph paragraph = document.createParagraph();

//Set bottom border to paragraph
paragraph.setBorderBottom(Borders.BASIC_BLACK_DASHES);

//Set left border to paragraph
paragraph.setBorderLeft(Borders.BASIC_BLACK_DASHES);

//Set right border to paragraph
paragraph.setBorderRight(Borders.BASIC_BLACK_DASHES);

//Set top border to paragraph
paragraph.setBorderTop(Borders.BASIC_BLACK_DASHES);

I found how to define the Page Margin size, but it doesn't helped me to put borders:

       CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
       CTPageMar pageMar = sectPr.addNewPgMar(); 
       pageMar.setLeft(BigInteger.valueOf(720L));
       pageMar.setTop(BigInteger.valueOf(360L));
       pageMar.setRight(BigInteger.valueOf(720L));
       pageMar.setBottom(BigInteger.valueOf(360L));

It is possible to create a bunch of paragraphs that have a bottom border defined. If all of the paragraphs have the same indentation (which could be reasonable to assume) a border is generated at the bottom of the page.

This is not consistent with what I would define as the desired behavior; so, I, unfortunately, didn't save a copy of this to share as reference. I'm sharing this in hopes it might help give you a place to start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM