【发布时间】:2014-08-07 08:43:36
【问题描述】:
我使用 Java 创建了一个文件,我想更改页边距但我不能
这是我的代码:
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setNumID(BigInteger.ONE);
run.setFontSize(18);
run.setText("Test");
try{
FileOutputStream output = new FileOutputStream("C://WordDocument.docx");
document.write(output);
output.close();
} catch (Exception e){
e.printStackTrace();
}
我想做的是document.setMarginLeft( Left_Margin );和document.setMarginRight( Right_Margin );之类的东西
提前致谢
【问题讨论】:
-
查看接受的答案:stackoverflow.com/a/17852064/1209205 使用
CTPageMar -
我在发布我的问题之前已经看到了,不幸的是找不到“CTPageMar”。 Eclipse 建议用它创建一个类。除非如果需要添加库,但通常eclipse会推荐请求的库。
-
您是否确定您使用的是最新版本的 Apache POI,并且您的类路径中有 all of the appropriate Apache POI jars and their dependencies?
标签: java ms-word apache-poi