In our desktop environment, I achieved the best combination of performance, flexibility, and stability using Excel through COM.
Access to Excel is always through one stream.
I use late binding (in VB.Net) to make my version of the application independent.
The rest of the application is developed in C #, only this part and some other small parts are in VB, because they are easier in VB.Net.
Dim workBook As Object = GetObject(fileName) Dim workSheet As Object = workBook.WorkSheets.Item(WorkSheetNr) Dim range As Object = workSheet.Cells.Item(1, 1) Dim range2 As Object = range.CurrentRegion Dim rrow As Integer = range2.Row ' For XL97, first convert to integer. XL97 will generate an error ' Dim rcolumn As Integer = range2.Column Dim top As Object = workSheet.Cells.Item(rrow, rcolumn) Dim bottom As Object = top.Offset(range2.Rows.Count - 1, range2.Columns.Count - 1) range = workSheet.Range(top, bottom) Dim values As Object(,) values = range.Value
Here you have a two-dimensional array containing values ββfrom Excel. The last statement gets data from Excel to .Net.
Since the limits on the size of the Excel worksheet, they cannot be very large, so memory should not be a problem.
We conducted several performance tests on several systems. It is optimized to make as few (out-of-process) COM calls as possible.
This method provided us with better performance, especially because the data is located directly in the array, and access to this data is faster than through a data set.
In this solution, Excel starts slowly. But if you need to process several files immediately after each other, the cost of running Excel is only done once.
Also, I would not use this solution in a server environment.