I have data that I’m taking from an Excel sheet with the ultimate goal of displaying in a DataGridView.
Currently I am just going over the UsedRange of excel data and plugging it into a datagridview. This works fine, but can get bogged down when there 100+ rows of data.
I have also toyed with going from excel into a dataset (using the same wasteful method), and as expected it takes about the same time to load the data.
I was wondering if anyone had any information for a better way? Maybe use the XML from the Excel file?
EDIT:
Some Additional Information:
This is a WinForms application and the user will be picking and loading the excel file at run-time.
EDIT
The Return of Some Additional Information:
The Excel file is located on the user’s pc. The general assumption is that they will be loading different files each time they use the application. [not sure if this helps, but might be good to know :)]
I faced this same problem recently…I wasn’t able to really find an out-of-the-box solution that would do this for me, so I ended up writing some code by hand.
I actually have two different solutions in my code library: one uses OLEDB and the other uses Excel Interop. From your question, I’m guessing you’ve been attempting to use an interop solution, and it’s too slow. If all you want to do is read tables directly from Excel, where there is one table per worksheet, the OLEDB solution is probably cleaner and faster. If you ever get to the point where you need to write to an Excel file, though, you may find that OLEDB is just too limited. That was my experience for one project.
Anyway, I’ll post a few bits and pieces from my OLEDB solution that will hopefully get you started:
Here is the code for the
ExcelConnectionProvider:If you run into any problems with this compiling, try including the “System.Data.DataSetExtensions” assembly in your project.
EDIT:
: IConnectionProvideris not needed — it’s an interface I added to my library because I have other connection providers besides Excel.