Tekito
Tekito

Reputation: 860

Need a faster Excel interop method

It appears to be common knowledge that interop with Excel and .Net is very slow. I'm aware of the ability to copy an array of values to a worksheet object in one go, but according to my stopwatch even one command (inside VB.Net) of the type:

 WS.Range(--range string here--).Value = array

...takes over 0.3 s! This adds up since my routine writes dozens of arrays to each worksheet, and there are several worksheets per workbook, and I'll probably be iterating through several workbooks as well.

If there was a way to write discontinuous, non-rectangular groups of cells at once, then I could do an entire WS with one write command. But I don't think there's a way to do that while preserving original values for the "inbetween" cells. These workbooks are pre-formatted so I have to leave particular cells as is.

Anything I can do to speed this up?

Upvotes: 1

Views: 1103

Answers (2)

RvdK
RvdK

Reputation: 19790

I don't know exactly if this is possible but you look into a library which does the same thing: NPOI. It can read and write from/to Excel documents. Using this made my application a lot faster (getting data from xls into C# app)

Upvotes: 0

Tekito
Tekito

Reputation: 860

Ben's comment above pretty much nailed it; excel's formula calculations were the bottleneck. I'm relieved, because I knew .Net-Excel interop had a reputation for being slow, but didn't think it was that slow.

Upvotes: 2

Related Questions