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

WEGSY85

Is there a way to set a default font family to a word document generated by Apache POI instead of setting the font family to each XWPFRun?

WEGSY85

I created a new method

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;
}

Then I call it like that:

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

or more generic:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how change text direction(not paragraph alignment) in document in apache poi word?(XWPF)

Set image position and tilt into a word .docx document using POI XWPF

How to change table direction in Apache word poi (XWPF)?

How to set the global font of word file via Apache poi?

Set font style for entire word document - VBA

Apache POI Word XWPF table direction and alignment

Apache-poi Java: How can I change the font name and size of a list numbering in a WORD document?

Apache Poi - XWPF: How to change font color, size, style of the footer Page Number in docx

Apache POI XWPF : How create a group of line?

How to set default font family for entire Android app

Add image into a word .docx document header using POI XWPF

java poi XWPF word - create bookmark in new document

Is it possible to set a default table style in Apache POI XWPF?

Replacing a text in Apache POI XWPF

Apache POI library : How to read Excel sheet embedded in Word document

how to add images side by side word document using apache poi

How to implement the Hanging Indent in Word document with Apache poi?

How to add a hyperlink to image in a Word document using Apache POI?

How to set font color rgb in excel via apache poi

How to set bold font using the latest apache poi?

How to set text font using Apache POI PPT API?

How to set table dimensions and spacing in word using apache poi in java

Apache POI - Split Word document (docx) to pages

Apache Poi Word document opening gives NullPointerException

apache poi add table in word document

Editing Word Document using Apache POI

Unable to change orientation of ms-word file(XWPF) using apache poi

Apache POI XWPF - Check if a run contains a picture

Apache POI XWPF adding shapes to header