简体   繁体   English

Java apache POI-如何用poi换句话说,每个页面都有边框?

[英]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. 我正在分享此信息,希望它可以为您提供一个起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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