Click here to Skip to main content
11,706,803 members (46,381 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Word Chart
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:
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 10-Apr-13 5:01am
LBJ76404
Edited 10-Apr-13 5:10am
(no name)502.4K
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 140
1 OriginalGriff 125
2 chainerlt 110
3 ppolymorphe 109
4 Mika Wendelius 70
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,487
2 CPallini 5,189
3 Maciej Los 4,766
4 Mika Wendelius 3,696


Advertise | Privacy | Mobile
Web01 | 2.8.150819.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