Hello All,
It's been a while since I have been on the forums but wanted to pick some brains out there.
I have recently been tasked with fixing up and modifying a process that relied heavily on VBA to pull a bunch of data out of spread sheets, package them up as documents and send them off to some web services. The structure of the documents are fairly complicated so I liked the idea of creating classes that form a DSL for building these things.
I remember seeing Mikael Katajamäki's blog post about creating COM objects in C# and exposing them to VBA using Excel DNA:
Looking at the article it seemed a natural fit for my problem and also can help me to remove a lot of this VBA with .NET classes that I can easily version control, unit test and all the other benefits that you get with having your logic in an Excel-Dna add-in.
Enough background... on to my question....
Within the VBA there are sections of the code where arrays of data (doubles and dates mostly) are read from Ranges. What are people's recommendations of how to either pass this data in or have my program read from these ranges?
Here are my rough - unorganized thoughts so far:
- Ideally I'd like to pass typed arrays but Excel doesn't seem to like it when you have a function signature in your ComVisible object that takes an array of either object or DateTime, which makes sense since there is a bunch of Marshalling magic that needs to happen.
- I could just pass the range or array as an object and then pull the values out using dynamic or reflection but was hoping for something a little more type safe.
- I would like to avoid using Primary Interop Assemblies so that I am not tied to a specific version of Excel.
Any advice would be most appreciated.
-Harley