ArticlesBlog

C# Tutorial – Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn

C# Tutorial – Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn


Welcome to FoxLearn In this tutorial, I’ll show you how to open, read and import excel file to DataGridView in c# using the ExcelDataReader library Open your form designer, then drag TextBox, Button, Label, Combobox and DataGridView from the visual studio toolbox to your winform Next, We will design a simple UI that allows you to select the excel file then load data from the excel file to DataGridView based on the sheet name you selected from the Comboxbox Right-click on your project, then select Manage Nuget Packages Next, You need to install the ExcelDataReader library to your project This is a lightweight and fast library written in c# for reading Microsoft Excel files Add the click event handler to the Browse button allows you to select the excel file, then open and read all sheet data You can use the CreateReader method of the ExcelReaderFactory class to read the excel file Data that you read from excel file will be returned as DataSet Next, you need to read all table names in the DataSet, then add the table name to the Combobox Finally, you need to specify the table name you want to retrieve the data, then bind the data to the DataGridView Thank you for watching this video and don’t forget to subscribe to my channel

Comments (19)

  1. Great video. Can u plz make in vb.net also? Thanks.

  2. could you please provide the source code of this program, also is it fine to use it in my projects?

  3. Are you able to write to excel files?

  4. how could I do this same process but to export from GridView to Excel using some library?

  5. can you help in asp.net how to read a excel file and use that excel sheet by culum in combo box its all value add

  6. Great tutorial!

    I'm wanting to take the data stored in specific rows and use with another button, how would I be able to use the data from cboSheet in a button? I'm guessing I need an array to store the row data?

  7. iv a two pbs
    1. that when i click or select the sheet again so it reads the excel again and that wht idn want have
    2. when the sheet is empty so ive to show a messagebx that the Sheet empty si how i can check if the Sheet empty or not thank you so much 🙂

  8. Thank you guys, this is the best channel every for programmers, always brings the new.. Thanks a million.

  9. hi, Thanks for the guide.
    I have problem with the line:
    "DataSet result = reader.AsDataSet…"

  10. All I have is CreateBinaryReader and not CreateReader

  11. datagridview doesn-t contain a definition for 'items'

  12. thank you very much for the tutorial 🙂

  13. This code doesnt work for me I get The name 'InitializeComponent' does not exist in the current context

    The name 'InitializeComponent' does not exist in the current context

  14. hi bro can i have this app source code but i have very emergency need to this 🙁

  15. Thank you so much for this guide!! <3

  16. Ato Fast Kaj KOrla kivabe sikba ?

Comment here