Background: I’m trying to make a decision on whether to go down the road of automating Excel using C# via Interop. I’m certainly not a VBA guy and for numerous reasons, I’d prefer not to go down that road. I don’t know much about other options, and I’m really not looking to buy anything.
Performance is massively important.
I’ve tried to find references on using Interop to automate Excel and it seems rather sparse. Some of the better stuff is dated and other references just don’t cover a lot of the material. Many folks cite the fact that a lot of the existing material spends time focusing on differences in version of MS Office. I’m also wondering whether the improvements that have been claimed with moving to .NET 4 are material.
Edit: The crux of what I’m trying to accomplish is complete automation of fairly involved and intricate formatting as well as some pretty heavy analysis (linear regression). I need to chart data once analyzed/calculated and the chart formatting is really important because the MBA’s I work with say it is. I guess all of this is possible via VBA but I don’t know for sure because I’m not a VBA guy. Think macro type stuff with the app hidden so it’s running as a background process. Performance is critical (one of the reasons I question COM’s appropriateness). VBA may even be off the table due to its performance considerations.
Now, for the question.
The best way I can ask this succinctly is: is there a laundry list of stuff you can’t do with Interop in Excel that you’d like to be able to do? How have you gotten around it in your development experiences?
If there really isn’t anything you can’t do with Interop (see comments below) and it’s the best fit for what I’m intending to do, what is the best way to go about learning to use it given that COM and the Excel object model can be a fairly intimidating undertaking. Are there really good references out there?
If there’s a better way for me to go about the above, can you tell me about it? Excel DNA was mentioned but I can’t see it being much more helpful than allowing the creation of user-defined C# functions that can get to a backend server app or database somewhere.
There is no correct answer to your questions: it all depends on the details and the background.
Interop performance when interacting with the Excel object model (get/put data formatting charts etc) will always be relatively slow because of the additional layers on top of COM.
.Net calculation speed can be faster than VBA calculation speed particularly with poorly written VBA code.
The .NET framework is much more powerful and complex than the VBA framework.
The Excel object model is large and complex. The VBA macro recorder can be helpful with this but produces apalling code.
The XLL interface is faster than COM but exposes less of the Excel object model.
Given your description my guess is that you would get better performance, ease of learning and use with VBA rather than than .NET because it seems likely that the majority of time will be spent interacting with the object model rather than doing linear regression calculations (which are not IMHO particularly CPU intensive).
But of course other considerations might make you prefer .NET