Read and Write Excel in C#

In this article I'm going to explain how to read and write data from Excel file with cell by cell. Recently I'm in a situation to update or modify the data in each cell. If I go with Excel there is no option to update the data cell wise but when we go with Excel we can read / write / update data cell by cell, but coming back to performance it's little bit down as compare with Csv but in a situation to read / write/ update cell information Excel is the best option.

Read and Write Excel:

Index:

1. Description:

In this article I'm going to explain how to read and write data from Excel file with cell by cell. Recently I'm in a situation to update or modify the data in each cell. If I go with Excel there is no option to update the data cell wise but when we go with Excel we can read / write / update data cell by cell, but coming back to performance it's little bit down as compare with Csv but in a situation to read / write/ update cell information Excel is the best option.

In this article I will show you how to handle Excel file using C#.

To achieve this you have to include the dll of Microsoft.Office.Interop.Excel dll as a reference to the project.

To add the dll right click on project reference and click on .NET tab and choose the Microsoft.Office.Interop.Excel and add it to your project reference.

2. Read Excel File:

I just pass the path of the file as input and if you want to read data from particular sheet then pass the sheetName as input parameter, and return the data in table format and store the same in DataTable.

3. Write Excel File:

This mehod help us to write data into Excel file with cell by cell, while handling with Excel we have to be very carefull to Release the objects once the work is done. If not it might be big issue while writing the next record and the file is unable to open since it is Read by some one else and it shows the error like File is ReadOnly mode it is being Edited by someone else.