By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,774 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,774 IT Pros & Developers. It's quick & easy.

C# & Interop.EXCEL9.dll

P: n/a
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
May 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

I don't think you reference the Interop, I think the interop is what is
created....when you reference a COM object.
It what allows .net to talk to com. But it isn't a substitute for the COM
object itself.
Click the "COM Compontents" tab, and reference
Microsoft Excel Lib ..

See my blog:
http://spaces.msn.com/sholliday/ 9/22/2005
or
http://www.sqlservercentral.com/colu...gxpexcelxmland
openxmlfordataimports.asp

"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:12*************@corp.supernews.com...
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

May 17 '06 #2

P: n/a
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

sloan wrote:
I don't think you reference the Interop, I think the interop is what is
created....when you reference a COM object.
It what allows .net to talk to com. But it isn't a substitute for the COM
object itself.
Click the "COM Compontents" tab, and reference
Microsoft Excel Lib ..

See my blog:
http://spaces.msn.com/sholliday/ 9/22/2005
or
http://www.sqlservercentral.com/colu...gxpexcelxmland
openxmlfordataimports.asp

"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:12*************@corp.supernews.com...
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


May 17 '06 #3

P: n/a
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);

"Brent" <""b b i g l e r "@ y a h o o ." wrote:
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

May 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.