Search code examples
javapowerpointopenxmldocx4j

pptx4j duplicate data when drawing graphs


I must have a bad understanding of OpenXML, but I do not understand why when drawing a graph in a power point presentation using docx4j, one must :

  • create an embedded excel file (data.xlsx) with data series
  • create an xml file (chart_data.xml) with link to data series

AND

  • populate chart_data.xml with strCache elements containing data from data.xlsx. We are duplicating the data series.

It seems like power point only uses elements from strCache to populate its graph. If they are missing, the graph is not displayed.

Why do we need to create both an excel worksheet and an xml file with the same data in it ?

Are the link we declare between the graph object and the embedded excel sheet used for something ?


Solution

  • If you use PowerPoint to create a pptx and insert a chart, it adds the XLSX as well.

    In the chart part's xml, the c:externalData element points to the XLSX.

    If you don't have the c:externalData element, you don't need to create the Excel worksheet. But leaving it out affects user's ability to edit the chart in Powerpoint.

    Curiously, c:externalData has child c:autoUpdate but it doesn't work as described at http://webapp.docx4java.org/OnlineDemo/ecma376/DrawingML/autoUpdate.html

    Above is based on testing in Powerpoint 2010 only; things may be different in 2013 or 2016.