Skip Navigation LinksHome > Categories > Code from a Category

Read and Write Excelsheet Data Using C#



User Name: codelecturer
Name: Mike Chauhan
Contact Me: www.datawebcoder.com/ContactUs.aspx
Home Page: www.datawebcoder.com
6 years of total IT experience including programming, application development, System Maintenance . 3 years of Experienced and expertise in .Net Framework VB, Visual Basic.Net, ASP.Net 2.0, 3.5 and AD... [More]
Viewed Times: 746
Add Date: 01/03/2012
In this article we are going to see how to use an excel sheet as a source to load data in windows application or a web application and use the same to export back to the excel sheet using C# and VB.net.
This requirement is straight forward used in day-to-day activity, but most of the time end up messing in some section of the code.

Overview:

Normally when requirement comes with accessing the data from the excel sheet, we first choose to start with the office interop assemblies (Office Automation Assemblies) and make a connection to the excel sheet and start processing but it has some disadvantages using it over the web(Check this link for more details Issues). So the alternate option was to use the OLEDB Provider to read the data and use it for the front end with an additional parameter of passing the connection string to the excel sheet.

Now we consider that we have things ready to export and import data to the excel sheet and the data is available in a dataset or a data table. We can use the below code snippet's to get the data passed to and fro to the excel.

The Below code snippet will be used to export the data from local to EXCEL Sheet.

Code : Writing data to Excel sheet


Code : Reading data from Excel sheet


Conclusion:

So in this article we have seen on how to do small manipulation of reading and writing excel data using C# which we normally require in our day-to-day coding.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.