I am using OpenXML SDK to generate Word Documents in C#. When it comes to chart, it does not support Edit Data in Excel functionality.
I found some sample code here to generate a chart. Please right-click the chart area and then choose Edit Data, nothing happens. https://code.msdn.microsoft.com/office/How-to-create-Chart-into-a7d424f6
The expected behavior is opening Excel with data.
I also tried with another popular OpenSource library Xceed Docx https://github.com/xceedsoftware/docx
The same issue is there also. Syncfusion does support this feature with a license cost.
How can I achieve this feature using OpenXML SDK or DocX or any other open source library?
Edited Nov'30 - I am aware of creating a document from a template (the template has a chart already, and it supports Edit Excel feature) and then either copy it/generate code and then updates the chart values using OpenXMLSDK PowerTool/ OpenXMLSDK Productivity Tool.
ex: OpenXmlPowerTools.ChartUpdater.UpdateChart() http://ericwhite.com/blog/update-cached-data-and-embedded-xlsx-for-charts-in-docx-pptx/
I am looking for creating a chart in a fresh document like syncfusion component. Syncfusion doesn't expect any template.
Any help would be appreciated. Thanks
Yes, this is possible using the free OpenXML SDK and the OpenXML Productivity Tool. Follow these steps:
Reflect Code
button at the top. The c# code needed to generate the document will be in the window on the right.WordChartGenerator
. For this project, type Install-Package DocumentFormat.OpenXML
in the Package Manager console. This pulls in the necessary DLLs for your project to use OpenXML.GeneratedClass.cs
and replace the entire contents using code generated from step 3.GeneratedClass.cs
to be
namespace WordChartGenerator
Go back to the Program.cs file and inside of main, instantiate an instance of the GeneratedClass class and call CreatePackage with a path to the desired full file path name. Something like the following:
class Program
{
static void Main(string[] args)
{
var wordGenerator = new GeneratedClass();
wordGenerator.CreatePackage("C:\\Users\\jeff\\Documents\\WordWithChart.docx");
}
}
run the program and it will generate your file in the directory you specify.
The below screen shot is from a file generated with these steps