I'm trying to use mine defined(changed) styles in
Styles styles = mp.getStyleDefinitionsPart ().getJaxbElement ();
to change styling for my entire table/individual table cells. I managed to make it by setting the properties in RPr runProperties like this:
in method applying style for table cells I use this:
setFontFamily(runProperties, style.getFontFamily());
private static void setFontFamily(RPr runProperties, String fontFamily) {
if (fontFamily != null) {
RFonts rf = runProperties.getRFonts();
if (rf == null) {
rf = new RFonts();
runProperties.setRFonts(rf);
}
rf.setAscii(fontFamily);
}
}
the same goes for other style attributes like font size, color etc. and it all works BUT ... The problem is that I use this to dynamically generate documents in Czech language, which has characters like: š, č, ř, ž, ý etc. and I use Verdana font for the table cell content and when I use this way to set the font it only applies characters different from Czech special characters.
So e.g. when I generate String "Pavlovský" into new docx, "Pavlovsk" is in Verdana font (as set) and the "ý" character is in Calibri font.
even if I simply use wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Normal", "íáýěéáěř");
- everything changes to Calibri (when I open the docx, style of paragraph is Normal - font Verdana ... as set in my code)
I even tried to set language like this
StyleDefinitionsPart styles = mp.getStyleDefinitionsPart ();
Style defaultCharacterStyle = styles.getDefaultCharacterStyle();
extracted(defaultCharacterStyle);
Style defaultParagraphStyle = styles.getDefaultParagraphStyle();
extracted(defaultParagraphStyle);
Style defaultTableStyle = styles.getDefaultTableStyle();
extracted(defaultTableStyle);
where:
private static void extracted(Style style) {
RPr rPr = style.getRPr();
if (rPr!=null) {
CTLanguage lang = factory.createCTLanguage();
lang.setVal("cs-CZ");
lang.setEastAsia("cs-CZ");
lang.setBidi("ar-SA");
rPr.setLang(lang);
style.setRPr(rPr);
} else {
rPr = factory.createRPr();
CTLanguage lang = factory.createCTLanguage();
lang.setVal("cs-CZ");
lang.setEastAsia("cs-CZ");
lang.setBidi("ar-SA");
rPr.setLang(lang);
style.setRPr(rPr);
}
}
I will be grateful for any hint! Thanks in advance!