Most efficient ways to work with large Excel ranges in C #?

I am working with Excel Interop in C # and writing code to do somewhat complex manipulation of tables with tens of thousands of rows of data. It works quite slowly.

I often have data stored in some sort of variable that I do some intermediate calculations before eventually writing the results to a worksheet.

I'm sure this is not a very good approach, but I often find myself creating a temporary worksheet that will be deleted when my code is complete, so I can use Excel methods on the Range property for the data, rather than trying to implement similar methods in an array. Most often, this includes things like sorting on multiple columns, removing duplicates, etc. These columns almost always have many different data types (strings, integers, numbers with two decimal places), although the actual data types stored in these cells do not always appear to be straightforward (for example, 100000000.01 is sometimes of type double, and in other cases it is decimal). The easiest way to deal with all the different types of data is to just use an Excel range, which is why my code often creates temporary sheets.and then removes them in my code.

What is the correct and effective way to handle these situations?

+3


source to share


1 answer


Take a look at these links



If you are updating individual cells that will be very slow. But in general, interel interop is slow. Do you think you can create a CSV file and then use excel interop to transform the final result?

+1


source







All Articles