Word 2000 and automating the creation of charts

P

PromisedOyster

I use Microsoft Word extensively to automate the production of graphs.
I am now attempting to create charts dynamically using the
"MSGraph.Chart.8" control.

Basically, there are 0 to many charts in a document. I iterate through
the charts in a document using the following code

_wordApp.Selection.WholeStory();
foreach (Word.InlineShape shape in _wordApp.Selection.InlineShapes)
{
}

I then attempt to populate the data on the chart and that is when
things go bad. For example:

Graph.Chart chart = (Graph.Chart)shape.OLEFormat.Object; // This
generates invalid case exception.
chart.Application.DataSheet.Cells[1, 1] = "11";

I believe the above works using Office XP, but not Office 2000?

Is there something I am doing wrong?
Perhaps there is an alternative way to achieve this without attempting
to case to a Graph.Chart object?

Notes:

When I add a reference for the graphs, I am using graph9.olb.
I have tried the ActivateAs method but to no avail.
Unfortunately we cannot force our users to Office XP.
 
C

Cindy M.

Hi PromisedOyster,
I use Microsoft Word extensively to automate the production of graphs.
I am now attempting to create charts dynamically using the
"MSGraph.Chart.8" control.

Basically, there are 0 to many charts in a document. I iterate through
the charts in a document using the following code

_wordApp.Selection.WholeStory();
foreach (Word.InlineShape shape in _wordApp.Selection.InlineShapes)
{
}

I then attempt to populate the data on the chart and that is when
things go bad. For example:

Graph.Chart chart = (Graph.Chart)shape.OLEFormat.Object; // This
generates invalid case exception.
chart.Application.DataSheet.Cells[1, 1] = "11";
In my experience, you first need to use Activate or DoVerb on the
*OLEFormat*, then you can assign and automate the object.
I believe the above works using Office XP, but not Office 2000?

Is there something I am doing wrong?
Perhaps there is an alternative way to achieve this without attempting
to case to a Graph.Chart object?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top