PC Review


Reply
Thread Tools Rate Thread

COMException on InvokeMember

 
 
-kve-
Guest
Posts: n/a
 
      11th Jul 2008
Hi,

I create an Excel chart in a Word document. I'm trying to change the chart
type at runtime (using late binding):

// Create the Word application and declare a document
Word2007.Application word = new Word2007.Application();
Word2007.Document doc = new Word2007.Document();

// Define an object to pass to the API for missing parameters
object missing = Type.Missing;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

word.Visible = true;

// Everything that goes to the interop must be an object
object fileName = string.Format(@"{0}\table.doc",
Path.GetDirectoryName(Application.ExecutablePath));

// Open the Word document.
object varFalse = false;
object varTrue = true; ;
// Create a new file based on our template
doc = word.Documents.Open(ref fileName, ref missing, ref varFalse, ref
missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref varTrue,
ref missing, ref missing, ref missing, ref missing);


//Insert a chart.
object oClassType = "Excel.Chart.8";
Word2007.Range wrdRng = doc.Bookmarks.get_Item(ref oEndOfDoc).Range;
InlineShape oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing);

object oChart = oShape.OLEFormat.Object;
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);


Here (on InvorkeMember) I get a COMException ("Unknown name. (Exception from
HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))")

My guess is that there is something wrong with the "ChartType" parameter...

I use Office 2007, but mu code should also work with Office 2003

Can anyone help me please?
 
Reply With Quote
 
 
 
 
-kve-
Guest
Posts: n/a
 
      15th Jul 2008
Found the problem:
I have installed an English Excel, but my regional settings are set to
another language...

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# GetType().InvokeMember Jason Huang Microsoft C# .NET 2 4th Nov 2009 01:52 PM
InvokeMember =?Utf-8?B?QW5nZWw=?= Microsoft Dot NET Framework 0 15th Feb 2006 05:37 PM
Help with Type.InvokeMember in C# Laurent Microsoft C# .NET 3 25th May 2005 06:51 PM
InvokeMember Amy Microsoft C# .NET 1 27th Feb 2004 08:57 AM
InvokeMember Chris Microsoft C# .NET 12 25th Jan 2004 10:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 PM.