Click here to Skip to main content
15,849,907 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I'm looking at autogenerating a department document and I want to auto generate a chart in this report. The code I got from the internet produces a dated looking chart but I want to be able to use more modern chart. I can find a way of changing styles for Tables but I cant see how I can change a style for a Chart. I'm guessing its something to do with me using MS Chart 8.0 instead of the latest version.

I can see plenty of articles using chart controls in applications but I have to generate this chart in word Programmatically

Code I currently use:
C#
Word.InlineShape oShape;
 object oClassType = "MSGraph.Chart.8";

 wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
 oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
     ref oMissing, ref oMissing, ref oMissing,
     ref oMissing, ref oMissing, ref oMissing);

 //Demonstrate use of late bound oChart and oChartApp objects to
 //manipulate the chart object with MSGraph.
 object oChart;
 object oChartApp;
 oChart = oShape.OLEFormat.Object;
 oChartApp = oChart.GetType().InvokeMember("Application",
     BindingFlags.GetProperty, null, oChart, null);


 //Change the chart type to Line.
 object[] Parameters = new Object[1];
 Parameters[0] = 4; //xlLine = 4
 oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
     null, oChart, Parameters);

 //Update the chart image and quit MSGraph.
 oChartApp.GetType().InvokeMember("Update",
     BindingFlags.InvokeMethod, null, oChartApp, null);
 oChartApp.GetType().InvokeMember("Quit",
     BindingFlags.InvokeMethod, null, oChartApp, null);

Would be much appreciated if someone can point me in the right direction
Posted
Updated 10-Apr-13 6:10am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900