使用Apache POI DOCX Word文档中的间距和边距设置 [英] spacing and margin settings in word document using Apache POI docx

查看:6633
本文介绍了使用Apache POI DOCX Word文档中的间距和边距设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个段落,我想在每行前100磅的空间。有没有一种方法,我们可以在的Apache POI 吗?

I have two paragraphs and i want 100 pt space before each line. Is there a way we can do in Apache POI?

下面是code段

XWPFDocument doc = new XWPFDocument();
XWPFParagraph documentTitle = doc.createParagraph();

documentTitle.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run = documentTitle.createRun();

run.setText("Paragraph 1");
run.setBold(true);
run.setFontFamily("Calibri");
run.setFontSize(13);
run.setColor("4F81BD");

run.addBreak();

run.setText("Paragraph 2");
run.setBold(true);
run.setFontFamily("Calibri");
run.setFontSize(13);
run.setColor("4F81BD");

下面如何在两个段落之间添加 100磅空间?有什么办法,我们可以做到这一点?
addBreak()未保持两条线之间的任何空间。

Here how to add 100 pt space between two paragraphs? Is there any way we can achieve this? addBreak() is not keeping any space between two lines.

和如何设置保证金间距的docx?

And how to set margin spacing in docx?

任何帮助将是AP preciated。

Any help would be appreciated.

感谢。

推荐答案

得到了答案。

    documentTitle.setAlignment(ParagraphAlignment.CENTER);
    // This does the trick
    documentTitle.setSpacingBefore(100);

这lefe我每行文本

It lefe me 100pt space between each line of the text

如果您想自定义边距添加到您的文档。使用code。

If you want to add custom margins to your document. use this code.

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

这篇关于使用Apache POI DOCX Word文档中的间距和边距设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆