Adding Chart to WordprocessingML
Asked Answered
J

3

8

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?

Juanitajuanne answered 14/2, 2009 at 16:20 Comment(0)
V
3

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.

Voodoo answered 25/3, 2009 at 21:38 Comment(0)
W
0

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

Wellbeing answered 24/2, 2009 at 19:58 Comment(0)
R
0

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.

Roofing answered 13/1, 2011 at 0:54 Comment(1)
I tried the same thing that you suggest, however problems comes from the embedded data for chart. When we use the code that is created from OpenXmlSDK it gives this embedded part(package) as binary data. However when you put the original .docx file to SDK you can see that it has .xlsx as embedded instead of the .bin. In conlusion , in original .docx we have .xlsx as embedded file ,however in created one (without making any changing) .docx we have .bin as embedded file.Ludmilla

© 2022 - 2024 — McMap. All rights reserved.