C# & Interop.EXCEL9.dll

B

Brent

I'm trying to open and manipulate an Excel spreadsheet from C#. To that
end, I've referenced Interop.EXCEL9.dll, which I have on my machine. All
of the examples I've read say to do something like this:

--------------------------

Excel.Application xl = new Excel.ApplicationClass();
xl.Visible = "true";
String workbookPath = @"c:\SomeWorkBook.xls";
Excel.Workbook xlW = xlW.Workbooks.Open(workbookPath,0, false, 5, "",
"", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false,
false);

-------------------------

Of course, I get an error on line 2 == "Visible" is not a valid property
of Excel.Application. Also, "Workbooks" is not valid.

So, I'm stumped.

I'd sure appreciate some help!

Thanks.

--Brent
 
B

Brent

Ah, yes...that's true. I referenced the "Microsoft Excel 9.0 Object
Library." The Interop file must have been created upon referencing. But
even with that reference -- which I believe is the correct one -- I'm
having the issues I described.

Thanks for your response! I'm still stumped, though! Should I reference
something else, too?

--Brent
 
G

Guest

did you create a shared add-in project ?

If you did ...

you should have this code

public void OnConnection( object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array
custom )
{
applicationObject = application;
addInInstance = addInInst;

}

Just add ...

Excel.Workbooks allWorkBooks = ( Excel.Workbooks
)applicationObject.GetType().InvokeMember( "Workbooks",
BindingFlags.GetProperty, null, applicationObject, null );

String workbookPath = @"c:\SomeWorkBook.xls";

allWorkBooks .Open(workbookPath,0, false, 5, "",
"", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false,
false);
 

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