Reducing access time to Excel

I am working in C # with Excel files using Microsoft.Office.Interop.Excel. My problem is that my program is very slow. Basically, it is that it iterates through the cells of the Excel sheet and reads the data in each of the cells.

I am using the following command:

value = (range.Cells[row, col] as Excel.Range).Value2;

      

where value is my variable and range is an Interop.Excel object of the Range class.

Is there a way to log into Interop to access an access file or some other library I should be using?

+3


source to share


2 answers


If possible use a library like EPPLUS which is much faster than interop and much easier to program.



If this is not possible due to external constraints, try to reduce the number of interop calls as much as possible. Looping in excel poses challenges - since each cell has to interact through interop, and it takes a long time to sort the data from excel to your application. It is much better to use get_Range () to get the entire array in one go. A single request will take a long time, but the C # loop is very fast after that. All in all, it's good to do whatever you can on the C # side, even if excel offers the same functionality.

+1


source


Excel Data Reader



Lightweight and super fast if reading is your only use case.

0


source







All Articles