如何使用 Apache POI 为 docx 文件中的段落设置标题样式? [英] How to set heading style for a paragraph in a docx file using Apache POI?
本文介绍了如何使用 Apache POI 为 docx 文件中的段落设置标题样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 poi 创建一个 docx 文件,但我无法为段落设置标题样式.
I am trying to create a docx file with poi but I cannot set heading style for a paragraph.
XWPFDocument document= new XWPFDocument();
//Write the Document in file system
FileOutputStream out = new FileOutputStream(new File("C:/Users/2/Desktop/RequirementModelDocument.docx"));
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run=paragraph.createRun();
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setStyle("Heading1");
run.setText(reqLevel.getName());
run.setBold(true);
run.setFontFamily("Calibri Light (Headings)");
它就像忽略了 paragraph.setStyle("Heading1");
行.我看过 apache 的例子,但我看不到任何关于这个问题的例子.
Its like ignores the paragraph.setStyle("Heading1");
line. I've looked at the apache's examples but I could not see any example about this issue.
推荐答案
我在下面的链接中找到了解决方案.抱歉重复.
I found a solution in the link below. Sorry for duplication.
但是,如果您有任何其他不使用模板文件的解决方案,请告诉我:)
But, If you have any other solution without using template file, please let me know :)
问候
这篇关于如何使用 Apache POI 为 docx 文件中的段落设置标题样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文