Why Apache POI XWPFRun.setFontFamily() for cyrilli

2019-07-12 18:50发布

问题:

I try to setFontFamily("Arial") to XWPFRun object with setText("Привет Hello") - cyrillic a english. English text will become Arial after this method call, but Russian text will be still at Colibri font family. How to create right font family for cyrillic text?

回答1:

Comment to setFontFamily() says:

Specifies the fonts which shall be used to display the text contents of this run. Specifies a font which shall be used to format all characters in the ASCII range (0 - 127) within the parent run

To other char try use CTFonts.setHAnsi, for example myXWPFRun.getCTR().getRPr().getRFonts().setHAnsi("Arial");

See bug https://issues.apache.org/bugzilla/show_bug.cgi?id=47148