Page 1 of 1

docx file looks different in Word 2010 versus 2013

PostPosted: Tue Mar 29, 2016 7:43 am
by sharon
I created the attached file file (created_using_docs4j.looks_different_in_Word_2010_vs_2013.docx) using docx4j but it displays differently in Word2010 versus Word2013 - the table is orange in 2010 and green in 2013. Can someone help me understand why?

I tried updating my template file (I use a template file to get all the styles I need) to a .dotx created from Word 2013 (created_using_word.looks_same_in_both_word_versions.docx) - this file looks the same in both 2010 and 2013. When I compare this new/template file to my docx4j-generated file the document xml seems the same (except for some minor differences such as column widths and justification) but I notice that my docx4j-generated file has no theme.xml. I'm guessing this is the issue. I updated my addTemplateStyles method (see code below) to include themes and fonts but it seems that by default the newly created-by-docx4j file does not include themes so I'm not sure how to add a theme part to the MainDocumentPart (see my question marks below).

I hope this information is sufficient to explain my question. I thought I'd try to keep this post on the less-verbose side :-)

Thanks for helping me understand!
Sharon


PS: The code I use to add styles from a template file is:

public static void addTemplateStyles(WordprocessingMLPackage wordMLPackage, File templateFile) throws Exception {
// Existing doc styles themes and fonts
MainDocumentPart actualDocPart = wordMLPackage.getMainDocumentPart();
StyleDefinitionsPart actualStyleDefinitionsPart = actualDocPart.getStyleDefinitionsPart();
ThemePart actualThemePart = actualDocPart.getThemePart();
if (actualThemePart == null) {
actualThemePart = new ThemePart();
// ???? How to attach it to actualDocPart ????
}
FontTablePart actualFontTablePart = actualDocPart.getFontTablePart();

// Add Template styles
WordprocessingMLPackage templateMLPackage = WordprocessingMLPackage.load(templateFile);
MainDocumentPart templateDocPart = templateMLPackage.getMainDocumentPart();
StyleDefinitionsPart templateStyleDefinitionsPart = templateDocPart.getStyleDefinitionsPart();
Styles templateStyles = templateStyleDefinitionsPart.getJaxbElement();
actualStyleDefinitionsPart.setJaxbElement(templateStyles);

// Add Template Themes <-- Adding this
ThemePart templateThemePart = templateDocPart.getThemePart();
Theme templateTheme = templateThemePart.getJaxbElement();
actualThemePart.setJaxbElement(templateTheme);

// Add Template Fonts <-- Adding this
FontTablePart templateFontTablePart = templateDocPart.getFontTablePart();
Fonts templateFonts = templateFontTablePart.getJaxbElement();
actualFontTablePart.setJaxbElement(templateFonts);
}

Re: docx file looks different in Word 2010 versus 2013

PostPosted: Tue Mar 29, 2016 11:52 pm
by sharon
I should also add that I've checked the styles xml in both docx files and the style I am using is in both. (I've tried LightGrid-Accent6 and GridTable4-Accent6, anything with alternate rows shaded orange is what I'm after) :-) The table looks great in both docx files but just in different colors - I'll try to learn more about themes (that must be the issue since document and styles xml look okay to me). Any hints appreciated..

Re: docx file looks different in Word 2010 versus 2013

PostPosted: Wed Mar 30, 2016 12:30 am
by sharon
Ah. I found the answer:

MainDocumentPart actualDocPart = wordMLPackage.getMainDocumentPart();
StyleDefinitionsPart actualStyleDefinitionsPart = actualDocPart.getStyleDefinitionsPart();
ThemePart actualThemePart = actualDocPart.getThemePart();
if (actualThemePart == null) {
actualThemePart = new ThemePart();
actualDocPart.addTargetPart(actualThemePart);
}
FontTablePart actualFontTablePart = actualDocPart.getFontTablePart();
if (actualFontTablePart == null) {
actualFontTablePart = new FontTablePart();
actualDocPart.addTargetPart(actualFontTablePart);
}

Yah! Thanks!