none
how can I operate Charts in word ? RRS feed

  • Question

  • At first I created a Word document like that :

    Then I use the Microsoft.Office.Interop.Word API to change the data of the Charts dynamicaly like that:

    ......

    Microsoft.Office.Interop.Word.Chart sh = (Chart)wordapp.Selection.InlineShapes[1].OLEFormat.Object;

    ...

    for(...){

           sh.Application.DataSheet.Cells[x,x] = ......;

    }

    Questions:

    1.I think this method is too verbose.Can I do this in any other way?

    2.There was a strange problem:I can operate The Microsoft Graph Chart .But I don't know how to operate the other type of charts.How many types of charts in Word? And how Can I change the data of them?

    Thank you very much.



    赵召

    Wednesday, April 16, 2014 1:43 AM

Answers

  • Whether you can change the Chart's data will depend on which charting engine was used to create the chart. Assuming the "native" Office 2007, 2010 or 2013 charting engine then you need to look at working directly with the Open XML content of the file (not using Word automation).

    Andy_mic has directed you to the Open XML SDK, which would be the correct approach in this case. You may also want to spend some time researching at OpenXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, April 24, 2014 4:32 PM
    Moderator

All replies

  • 1. What do you find verbose? You don't show us all your code, so it's difficult to judge whether you're doing things that could be shortened.

    2. The answer to this depends on which version of Office is installed and what other software - that can make charts - is installed on your machine as an OLE Server.

    MS Graph is the old, pre-Office 2007 charting engine; a new one was introduced in Office 2007 that has a different object model. The code you show us is for the newer charting engine, not MS Graph.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, April 16, 2014 1:28 PM
    Moderator
  • I'm sorry so long to reply your letter.Now the problem is this:

    In the word documents I insert a chart.And in My web application ,I want to update the charts data.

    1.how can i get the Chart?

    2.how can i change the data of the chart?

    Can someone answers with the detail code ?


    赵召

    Thursday, April 24, 2014 3:16 AM
  • Please use OpenXML SDK to operate Office document on server side.

    Have a look at this sample:

    http://www.codeproject.com/Articles/188909/Updating-Charts-in-Word-Document-using-OpenXML

    Thursday, April 24, 2014 5:35 AM
  • Whether you can change the Chart's data will depend on which charting engine was used to create the chart. Assuming the "native" Office 2007, 2010 or 2013 charting engine then you need to look at working directly with the Open XML content of the file (not using Word automation).

    Andy_mic has directed you to the Open XML SDK, which would be the correct approach in this case. You may also want to spend some time researching at OpenXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, April 24, 2014 4:32 PM
    Moderator