Click here to Skip to main content
11,922,026 members (38,146 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Word Chart

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:
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.
     BindingFlags.InvokeMethod, null, oChartApp, null);
     BindingFlags.InvokeMethod, null, oChartApp, null);
Would be much appreciated if someone can point me in the right direction
Posted 10-Apr-13 6:01am
Edited 10-Apr-13 6:10am

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

  Print Answers RSS
0 OriginalGriff 493
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 243
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,231
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,356
3 George Jonsson 2,865
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100