473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C# & Interop.EXCEL9.dll

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
3 5097

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: roy | last post by:
I try to call com written in VB 6.0. When I use VS.net Studio to do the debuging, some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation'...
1
by: Bob N5 | last post by:
I am working on an application that uses interop to do some simple operations with both Excel and Word. I have most of functionality working, but ran into issues on making things work with both...
0
by: Maxim Kazitov | last post by:
Hi, I try to create ObjectBrowser for some COM objects (C# project, I use Interop Assembly for COM). But if following code : Type oType = m_Object.GetType(); always return __ComObject...
10
by: Michi | last post by:
Hi Does anybody know how I can display own icons for drag & drop ? thx
2
by: Steve | last post by:
I'm using Visual Studio .NET (not 2003), and am developing a class that works with Word theough the Office PIAs (Interop). I can open word and do things with it programatically, but I can't close...
2
by: 1944USA | last post by:
I am re-architecting a C# application written as a multithreaded Windows Service and trying to squeeze every bit of performance out of it. 1) Does the thread that an object is instantiated on...
9
by: Lloyd Dupont | last post by:
If I write a pure C# application, only using the standart publi API, no interop, the same binary should work well on32 bit, 64 bits and perhaps on the compact framework as well if I link against...
0
by: Roman Optio | last post by:
Hi, I am currently working on a tool to transfer addressbook data such as contacts and organizations between Vondle and Outlook. For those of you who are wondering what Vondle is, it is an...
1
by: =?Utf-8?B?UmFq?= | last post by:
I want to understand why C++ interop has better performance than P/Invoke. Can someone explain in detail. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.