如何在 Apache POI XWPF 中为整个 Word 文档设置字体系列

How to set a font family to an entire Word document in Apache POI XWPF

有没有办法将默认字体系列设置为 Apache POI 生成的 word 文档,而不是将字体系列设置为每个 XWPFRun

我创建了一个新方法

public static XWPFRun createRun(XWPFParagraph paragraph, String     fontFamily, int fontSize, boolean bold, UnderlinePatterns underline){
    XWPFRun run = paragraph.createRun();
    run.setFontFamily(fontFamily);
    run.setBold(bold);
    run.setUnderline(underline);
    run.setFontSize(fontSize);
    return run;
}

然后我这样称呼它:

XWPFParagraph paragraphHeader = document.createParagraph();
XWPFRun runTextHeader = createRun(paragraphHeader, WordStyling.FONT_FAMILY_TIMES, WordStyling.FONT_SIZE_14);

或更通用:

public static XWPFRun createRun(XWPFParagraph paragraph){
    XWPFRun run = paragraph.createRun();
    run.setFontSize(12);
    run.setFontFamily("Times New Roman");
    return run;
}