Page 1 of 1

Adding themeOverride to Chart

PostPosted: Tue Aug 13, 2013 9:07 am
by lerien
I'm looking for the proper way to add a themeOverride to a chart without having to add the @XMLRootElement annotation to CTBaseStylesOverride and compile my own version of docx4j. I'm currently getting this Exception when I call SaveToZipFile.save():
Caused by: com.sun.istack.SAXException2: unable to marshal type "org.docx4j.dml.CTBaseStylesOverride" as an element because it is missing an @XmlRootElement annotation

Sample code:

Code: Select all
Chart c = new Chart(new PartName("/ppt/charts/chart" + (chartId) + ".xml"));
CTBaseStylesOverride override = new CTBaseStylesOverride();
//set override details here
JaxbXmlPart<CTBaseStylesOverride> overridePart = new JaxbXmlPart<CTBaseStylesOverride>(
new PartName("/ppt/theme/themeOverride" + (chartId) + ".xml"),
ContextFactory.getContext("org.docx4j.dml")) {
};

overridePart.setRelationshipType(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/themeOverride");
overridePart
.setContentType(new ContentType("application/vnd.openxmlformats-officedocument.themeOverride+xml"));

presentationTemplate.getParts().getParts().put(c.partName, c); //my PresentationMLPackage
         
overridePart.setJaxbElement(override);

c.addTargetPart(overridePart);

Re: Adding themeOverride to Chart

PostPosted: Tue Aug 13, 2013 1:41 pm
by jason
Hi, it'd be helpful if you could provide:

1 instructions for creating in Word a docx which has the part you describe
2 a sample docx

Then we'll be able to answer your question :-)

Re: Adding themeOverride to Chart

PostPosted: Tue Aug 13, 2013 3:56 pm
by lerien
Hi Jason. I'm working with a xlsx file and trying to copy the charts to a pptx file. Each chart has a themeoverride.xml file associated with it. For example if there is a chart in xl/charts named chart1.xml there is a corresponding themeOverride xml file in xl/theme. The relationships are found in xl/charts/_rels. An example relationship file for chart1.xml would be called chart1.xml.rels and contains the relationship to the corresponding themeOverride.

Re: Adding themeOverride to Chart

PostPosted: Tue Aug 13, 2013 5:41 pm
by jason
I'll add a dedicated object to represent a themeOverride part later today.

In the meantime, you can work around the marshalling exception by using a suitable JAXBElement. Here is some code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                org.docx4j.dml.ObjectFactory of = new org.docx4j.dml.ObjectFactory();
                org.docx4j.dml.CTBaseStylesOverride bso = of.createCTBaseStylesOverride();
                JAXBElement<CTBaseStylesOverride> themeOverride = of.createThemeOverride(bso);
               
                System.out.println(XmlUtils.marshaltoString(themeOverride, true, true));
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4

Re: Adding themeOverride to Chart

PostPosted: Tue Aug 13, 2013 7:49 pm
by jason

Re: Adding themeOverride to Chart

PostPosted: Wed Aug 14, 2013 4:21 am
by lerien
Jason, thank you SO much. That worked beautifully. :D