Trigger a macro inside an excel sheet from c# code

  • Thread starter Thread starter Fritjolf
  • Start date Start date
F

Fritjolf

Hi.

Is it possible to build a c# application that triggers a macro inside
av excel sheet (v2003 and v2007)?

If it is, does the machine that the application on have to have excel
installed?

A code example would be greatly appreciated.
 
Hi and thanx for your reply.

I have googled all day but I can't find any useful example code on how
to get this working in a .net application - without using COM.

I just want to add a reference to the .net library:
Microsoft.Office.Interop.Excel and not the COM version.

Does anyone have any code that simply triggers a macro within an excel
sheet?

Thanx in advance,

Fritjolf
 
By the way, are you sure you have to have Excel installed on the
machine?
If you use COM I agree, but ti seems you don't have to if you
use .net. ?

Thanx again.
 
[please don't top-post]
By the way, are you sure you have to have Excel installed on the
machine?
Yes.

If you use COM I agree, but it seems you don't have to if you
use .NET?

There is no Office automation built into the .NET Framework...


I'm sorry to be going on and on about this, but I really can't find
the answers I seek from googling - which I've been doing for the past
two days.

You say there is no automation build into the .NET Framework, but if I
"add reference" in a C# project and go to the .net page I can choose
Microsoft.Office.Interop.Excel. Is this not the .net framework library
for Excel Automation? I'm new to C# (as I'm sure you can tell...)

I also read an article of someone who accessed excel with the .net
framework on a server, not using COM because Excel was not installed
on the server. This is the reasons for previous questions (in previous
post).

Using the reference mentioned above I can access an excel sheet and
ie. count sheets. Are you saying this is done by COM and not by calls
to the .net framework?

I would greatly appreciate a good explanation.

I would simply like to access an excel sheet and run macros on it from
a C# application preferably running on a 2003 windows server.

Thanx in advance.

Fritjolf
 
That is correct. If there were, products like Aspose (see below) and GemBox
wouldn't need to exist...


That's because you have Microsoft Office Primary Interop Assembly for Excel
installed on your machine, either as a reult of installing Office or running
its own msi installer
(http://www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac1....).
These are COM wrappers for .NET apps to provide an easy method of automating
the various Office apps through their exposed COM interfaces:http://msdn.microsoft.com/en-us/library/microsoft.office.interop.exce...

http://www.dotnetspider.com/forum/106046-where-can-i-get-Microsoft-in...


No it isn't - there is no .NET Framework library for Excel Automation. The
clue here is "Interop" - whenever you see Interop, that is simply Microsoft
shorthand for interoperability between managed (.NET) and unmanaged (in this
case, COM) resources. Primary Interop Assemblies aren't restricted to
Office - you can make a PIA wrapper for any COM object, including ones you
have written yourself:http://msdn.microsoft.com/en-us/library/aa302338.aspx


You almost certainly read that they were using Aspose:
 http://www.aspose.com/categories/.net-components/aspose.cells-for-.ne....> Using the reference mentioned above I can access an Excel sheet and> ie.. count sheets. Are you saying this is done by COM and not by calls> to the.net framework?Yes, that is *EXACTLY* what I'm saying. The reference you mentioned above isusing the PIA wrapper for the Office COM objects.--Mark RaeASP.NET MVPhttp://www.markrae.net


Thank you VERY MUCH for your explanatory reply!!!!
Your reply has saved me from several hours of googling. Thank you very
much for taking the time!

Best regards,

Fritjolf
 
Back
Top