0

I have just started getting into Excel Interop and was wondering how I could improve the performance of my application by implementing either multithreading or multitasking.

My code looks something like this atm:

foreach(var path in arrayOfExcelFilePaths){
    excelApp.Workbooks.Open(path);
}
foreach(var wb in excelApp.Workbooks){
    //Read stuff and maybe write stuff
}

Thanks in advance for anybody looking into this.

3
  • I don't know if multithreading will imprve the read times if you're using a single instance of Excel. You could try creating a separate excel application for each workbook. Also, I'd try making sure my read operations are optimised before trying multithreading as that is usually the cause of poor exel interop IO. Commented Apr 18, 2020 at 15:49
  • Thanks for the response. What do you mean exactly by optimizing read operations? Commented Apr 18, 2020 at 16:04
  • What I mean is that your read operation should read all the data in one go into a an array. This is usually quite fast even for very large datasets. The slowness of interop is mainly due the marshalling between managed/unmanaged code and the IPC, so reducing the number of marshalling operations usually speeds things up considerably. If you like I can answer with more detail but I'd ask you to update your answer with some code of the read/write. Commented Apr 18, 2020 at 20:53

2 Answers 2

1

Using Interop is a bad idea in general. The execution of your code won’t differ much from its equivalent written in a VBA macro, because Interop simply runs the Excel process in the background and replicates its functionality 1-to-1.

Try OfficeOpenXML or any other library that allows you manipulate the content of excel sheets without running MS Excel as Interop does.

Sign up to request clarification or add additional context in comments.

Comments

0

I highly recommend you use the EPPlus 5 library, which is a newer version of the EPPlus library. Its fast and reliable, I've been using it for years without any issues.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.