Reflecting on Excel

Gabhan Berry has some really interesting (and potentially useful!) stuff that mainly centres around programming with Excel. One of the most interesting entries is one regarding dealing with Optional parameters in the Excel object model when using C# (Optional Parameters are supported by the CLR and, but not by C#). Whilst reflection is pretty cool and using it to achieve a solution to the Excel object models fetish for optional parameters is quite clever, personally I'd go for a wrapper class that I'd written which gives a set of different method signatures to accommodate my needs. Compile time checking is well worth having and eliminating the subtle bugs that can have me banging my head against the wall for hours that using reflection in this way introduces is a winner any day.

The common consensus, although I have no statistics or timings to prove or disprove this, is that using reflection is slower as well. If, for example, you were automating Excel to produce output / read input (yes, there are better ways to do this!) that contained a large amount of data, I imagine this could begin to make a significant difference to performance. On the other hand, choosing against reflection purely because of this could be considered a premature optimisation.

Of course, the other answer is to just use rather than C# ;)

About Rob

I've been interested in computing since the day my Dad purchased his first business PC (an Amstrad PC 1640 for anyone interested) which introduced me to MS-DOS batch programming and BASIC.

My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.

No Comments

Add a Comment