Adding Chart to WordprocessingML

1.4k views Asked by At

I would like to generate an Open XML document containing a Chart using the Open Xml SDK 2. I found an SpreadsheetML example, but I can't work out how to add the chart in a .docx...

Is there a good source for documentation/examples for the Open Xml SDK 2?

3

There are 3 answers

0
ajma On
0
Wayne Kao On

This article describes how to add a picture to WordProcessingML from an XML perspective: http://openxmldeveloper.org/articles/462.aspx

Actual code for the same thing using the Open XML API: http://msdn.microsoft.com/en-us/library/bb497430(office.14).aspx

If you've successfully added a chart to SpreadsheetML, you can adapt the picture example to do the same for WordProcessingML. You'll still have the a:graphic element that they have in their example. Contained inside, the a:graphicData will have a chart URI (http://schemas.openxmlformats.org/drawingml/2006/chart) instead of a picture URI. The data inside the a:graphicData will be identical to what you had for SpreadsheetML.

1
damoe On

Unfortunately there is a shortage of worked examples on the net. As always the simplest way when using the OpenXmlSDK is to create a word document with a chart and open it within the document explorer tool.

When I've inserted charts in the past they have been inserted as a "ChartPart" within the document, which had several child part relationships to the data source and formatting and then within the documnet Body itself a "c:chartReference" referred to the chart part by id. I believe the chartReference lives underneath a graphicData.