Excel performance through COM
I can only comment on your Q.3
Most of Excel's worksheet functions are extremely efficient when called in
cell formulas. However in code the call to the worksheetfunction library is
relatively slow, possibly slower with your C# addin even than in VBA.
If processing a small to medium qty of cells it's probably faster if you
roll your own function. With a large number though even with delay of
calling the function overall speed might be faster. Best way is to test with
a simple Sum routine.
Read and particularly Write to individual cells is slow. Generally faster to
read the entire range to an array, do your stuff, and write back the result
myArray = myRange.Value2 ' 2d array
loop myArray
For questions about Excel's object model you have come to the right place.
You may also find it simpler to devise routines in Excel VBA before adapting
to C#. For the rest of your questions, if you don't get answers here it
might be worth asking in a forum more dedicated to C# addins for Excel.
Regards,
Peter T
"Fabz" wrote in message
...
Hi there,
I am writing COMAddIns and Automation AddIns for Excel 2007 (with C#).
However, except a few sites, I cannot find any very helpful resources on
performance.
1. Does anyone know where I can find a precise description what accessing
the Excel Object Model through a COM interface really does? Am I accessing
"proxy objects" thus in fact marshalling calls from my C# code to Excel?
2. When calling myRange.Value2 do I in fact marshal a call through the COM
interface or not?
3. Question 2 leads to another question: Is is correct that using
Worksheetfunction.sum(myRange, ...) (1 marshalled call for all cells in
the range together) is much faster than using a loop and summing the cell
values in my own C# code (1 marshalled call for every single cell in the
range)?
4. When providing an Excel Range to a Worksheetfunction in my C# code,
does Excel actually remarshal the Excel Range and send it back to the
Excel application (e.g. copying all the values in the range) or does Excel
only send the cell reference (e.g. "A1:B10") to Excel and let Excel then
access the Range? Is there any way of doing something in my C# code like
Worksheetfunction.sum("A1:B10", System.Reflection.Missing.Value, ...)?
5. Does shimming my COMAddIn/Automation AddIn actually increase or
decrease performance (or doesn't it matter)?
Thanks for your answers.
Fabz
|