all groups > dotnet interop > march 2005 >
You're in the

dotnet interop

group:

Excel Automation


Excel Automation DebugUnlimited via DotNetMonster.com
3/11/2005 12:56:52 PM
dotnet interop:
Hi All,

I have seen lots of thread on HOW TO automate Excel. Many has also provided
answers to that. But none had provided a generic way that does not depend
on the version of XL.
I need a sample that is able to automate XL irrespective of the version
installed on other machine.

Can any body help me on this.

Thanks

--
Re: Excel Automation Fredrik Wahlgren
3/11/2005 2:24:46 PM

"DebugUnlimited via DotNetMonster.com" <forum@DotNetMonster.com> wrote in
message news:2983fd463e074ae89cae18135eaa0e7c@DotNetMonster.com...
[quoted text, click to view]

As long as you use .NET and you refer to the PIA, you can't. If you just
want to make some user defined functions, no problem. If you want one
solution that works with many versions of Excel and has it's own menus, your
best bet is VB6. If you don't mind C++, you can create either COM and/or
automation add-ins as well as xll's

Please tell what you want to do in more detail.

Best Regards,
Fredrik

Re: Excel Automation DebugUnlimited via DotNetMonster.com
3/12/2005 6:18:11 AM
Hi Fredrik!
I want to export data from SQL server to XL in a predefined format.
If i refer to the PIA, it works fine. Incedentaly i have office 2003
installed on my 2nd machine and Office 2000 pro on my first development
machine. Now when i open the same project on the 2nd machine, ity shoots
out error message during build, which refers to the refrence i made for
office 2000.
This made me think what if the client has diff verisons installed at his
place? I have used GetObject in VB (dynamic binding) and need some sort of
same thing in .Net C#.

Any ideas?

Thanks

--
Re: Excel Automation Andrew Hayes
3/31/2005 2:57:47 PM
Using Automation in C# is a pain, primarily because C# doesn't support
Optional parameters, and unfortunately MS usually just tagged on extra
parameters as Optional whenever they updated the automation interfaces.

This is why in VB6 you can late-bind an Excel object and the same method for
accessing the contents of a cell will work regardless of the version of
Excel.

There are reams of articles concerning Office Development with Visual
Studio:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/vsofficedev.asp

but very little about using Visual Studio.NET.

Anyway, I digress. An article you might find of use is:

Binding for Office automation servers with Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;302902

You might want to look at this too:

Applied Remoting
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet05272003.asp

Another solution that we have used ourselves is to write an Automation
wrapper in VB6 as an COM DLL that late-binds Excel and then reference it
from your C#.NET project. You have to do a big of jiggery-pokery to get the
COM component to expose it's interface so that C#.NET can use it, but apart
from that it works. Can't vouch for decent performance though since there's
lots of calls to IDispatch and other interfaces.

Regards...Andrew

P.S. Don't forget to modify the DCOM Config for the Microsoft Excel
Application.

AddThis Social Bookmark Button