How can I fill a chart in word?

H

Hooyoo

I use InlineShapes to insert a chart in a word document.
//Insert a chart.
object chartLocation = wordApp.Selection.Range;
wordDoc.InlineShapes.AddChart(
Microsoft.Office.Core.XlChartType.xlLineStacked,
ref chartLocation);
InlineShape shape = wordDoc.InlineShapes[1];
Next step, I want to fill data to the chart, but I don't know how to
manipulate InlineShape. Does anybody can help me ? Thanks a lot.

Another question is how to avoid Excel popping up when insert the
chart. When I insert a chart, an Excel will pop up to let me fill the
data, but I want to hide it, and fill chart with coding. Please help
me. Thanks again.
 
C

Cindy M.

Hi Hooyoo,
I use InlineShapes to insert a chart in a word document.
//Insert a chart.
object chartLocation = wordApp.Selection.Range;
wordDoc.InlineShapes.AddChart(
Microsoft.Office.Core.XlChartType.xlLineStacked,
ref chartLocation);
InlineShape shape = wordDoc.InlineShapes[1];
Next step, I want to fill data to the chart, but I don't know how to
manipulate InlineShape. Does anybody can help me ? Thanks a lot.

Another question is how to avoid Excel popping up when insert the
chart. When I insert a chart, an Excel will pop up to let me fill the
data, but I want to hide it, and fill chart with coding.
This is Office 2007, correct? The object model to manipulate a chart
created in this manner is not exposed. You'd need to insert the chart in
the "old-fashioned" way (as in previous versions). That goes something
like this (VB code):

Dim ils as Word.InlineShape
ils = doc.InlineShapes.AddOLEObject(ClassType:="Excel.Chart",
Range:=Selection.Range)

Dim of as Word.OleFormat
of = ils.OLEFormat
of.DoVerb wdOLEVerbOpen 'not in effect when creating, only when
editing

Dim xlWkbk As Excel.Workbook
Dim xlChart As Excel.Chart
Dim xlSheet As Excel.WorkSheet
'You'll need to explicitly cast these in C#
xlWkbk = of.Object
xlChart = xlWkbk.Sheets("Chart1")
xlSheet = xlWkbk.Sheets("Sheet1")


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 :)
 
H

Hooyoo

Hi Hooyoo,
I use InlineShapes to insert a chart in a word document.
//Insert a chart.
object chartLocation = wordApp.Selection.Range;
wordDoc.InlineShapes.AddChart(
Microsoft.Office.Core.XlChartType.xlLineStacked,
ref chartLocation);
InlineShape shape = wordDoc.InlineShapes[1];
Next step, I want to fill data to the chart, but I don't know how to
manipulate InlineShape. Does anybody can help me ? Thanks a lot.
Another question is how to avoid Excel popping up when insert the
chart. When I insert a chart, an Excel will pop up to let me fill the
data, but I want to hide it, and fill chart with coding.

This is Office 2007, correct? The object model to manipulate a chart
created in this manner is not exposed. You'd need to insert the chart in
the "old-fashioned" way (as in previous versions). That goes something
like this (VB code):

Dim ils as Word.InlineShape
ils = doc.InlineShapes.AddOLEObject(ClassType:="Excel.Chart",
Range:=Selection.Range)

Dim of as Word.OleFormat
of = ils.OLEFormat
of.DoVerb wdOLEVerbOpen 'not in effect when creating, only when
editing

Dim xlWkbk As Excel.Workbook
Dim xlChart As Excel.Chart
Dim xlSheet As Excel.WorkSheet
'You'll need to explicitly cast these in C#
xlWkbk = of.Object
xlChart = xlWkbk.Sheets("Chart1")
xlSheet = xlWkbk.Sheets("Sheet1")

Cindy Meister
INTER-Solutions, Switzerlandhttp://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 :)

Thank you. Appreciate that.
 

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