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?
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.
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.
I don't have an example for you, but look into cfchunks:
https://blogs.msdn.com/johnrdurant/archive/2005/07/15/cfChunk.aspx
http://blogs.msdn.com/brian_jones/archive/2005/07/20/441167.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.