Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Best way to read a XLS (XLSX) file and populate a datagrid

Tags:

c#

.net

excel

What is the best (free or paid for) to read Excel files (XLS and XLSX) using C# and populate a datagrid, I would also like to have any changes made in the datagrid be written back to the file.

I should also add that it needs to be high performing as the datagrid can contain a significant number of rows (10,000+).

This would be used for a commercial application so it would need to be distributable.

This is a Windows Forms application.

like image 610
LeeW Avatar asked May 27 '10 22:05

LeeW


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


1 Answers

I recommend databinding the datagrid to a dataset/datatable populated via the ADO.NET OleDb provider.

You'll find an example at Read from Excel using OleDb in a Windows Service?

I also found How To Use ADO with Excel Data from Visual Basic or VBA and How To Use ADOX with Excel Data from Visual Basic or VBA to be useful in knowing how to create a table (sheet) and access sheets and ranges.

It works very well for xls files. I haven't tried using it for xlsx.

like image 82
Alfred Myers Avatar answered Nov 12 '22 21:11

Alfred Myers