You can see the sample : How to create Chart in Word document using OpenXML
Creating Charts using OpenXML and append it to a bookmark in a word document C#
I need help creating a chart append it to a bookmark in a word document using OpenXML. I have tried creating a drawing object and then appending it to the document but that doesn't work. I need help from someone who can send sample code (C#) which instructs me how to properly create a chart and append it to a bookmark in a word document. Any help would greatly be appreciated.
Developer technologies C#
2 answers
Sort by: Most helpful
-
-
Timon Yang-MSFT 9,606 Reputation points
2021-09-06T07:11:56.007+00:00 This is a piece of code generated by the Open Xml SDK 2.5 Productivity Tool, just a blank word file with a bookmark, and then add a chart to the bookmark.
Since it is too long, I will provide it to you as an attachment, hoping to provide you with some ideas.
By the way, if it is not for special reasons such as the code must be run on a server or a machine without an office, the code written in Microsoft.Office.Interop.Word will be much simpler.
Application oWord = new Application(); Document oDoc = oWord.Documents.Open(@"C:\...\1.docx"); oWord.Visible = false; InlineShape oShape; Range wrdRng = oDoc.Bookmarks[1].Range; oShape = oDoc.InlineShapes.AddChart(Office.XlChartType.xlBarClustered, wrdRng); oDoc.Save(); oDoc.Close(); oWord.Quit();
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.