简体   繁体   English

将图表添加到WordprocessingML

[英]Adding Chart to WordprocessingML

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... 我想使用Open Xml SDK 2生成包含图表的Open XML文档。我找到了一个SpreadsheetML示例 ,但是我不知道如何在.docx中添加图表。

Is there a good source for documentation/examples for the Open Xml SDK 2? Open Xml SDK 2是否有很好的文档/示例资源?

This article describes how to add a picture to WordProcessingML from an XML perspective: http://openxmldeveloper.org/articles/462.aspx 本文介绍了如何从XML角度向WordProcessingML添加图片: 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 使用Open XML API进行同一操作的实际代码: http : //msdn.microsoft.com/zh-cn/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. 如果您已成功将图表添加到SpreadsheetML,则可以使图片示例适应WordProcessingML的要求。 You'll still have the a:graphic element that they have in their example. 您仍将拥有其示例中的a:graphic元素。 Contained inside, the a:graphicData will have a chart URI ( http://schemas.openxmlformats.org/drawingml/2006/chart ) instead of a picture URI. 包含在内部的a:graphicData将具有图表URI( http://schemas.openxmlformats.org/drawingml/2006/chart ),而不是图片URI。 The data inside the a:graphicData will be identical to what you had for SpreadsheetML. a:graphicData中的数据将与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. 一如往常,使用OpenXmlSDK时,最简单的方法是使用图表创建Word文档,然后在文档浏览器工具中将其打开。

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. 过去插入图表时,它们已作为“ ChartPart”插入到文档中,该文档与数据源和格式有多个子部件关系,然后在documnet正文本身中有一个“ c:chartReference”,它指向图表按ID划分。 I believe the chartReference lives underneath a graphicData. 我相信chartReference驻留在graphicData下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM