Create Excel sheet in C#.net using interop service

Here I am going to explain how to create excel sheet dynamically in c#.net using .net's interop service. Sometimes we need to create excel sheet from provided database's data and we need to save that excel file into a drive. With this interop service we can access each and every functions of Microsoft Excel.

Here I am going to explain how to create one excel file in C#.net using microsoft office interop service.

To Create Excel file follow the below steps :

Step 1 :

Add the Microsoft Excel 12.0 Object Library to your project.

--Create a new website and add a Command Button to the page. --To add Excel reference library in to your project see below picture.

Step 2 :

Select Add Reference dialogue from Website Menu

Step 3 :

Select Microsoft.Excel 12.0 Object Library and click OK button

Step 4 :

Now add Interop.Excel.dll to your projects bin folder and then add the reference to Interop.Excel.dll

To make reference to Interop.Excel.dll follow the same steps as above but instead of choose COM tab select Browse tab and then you can navigate to your bin folder and then click on Interop.Excel.dll and then click on OK

Download Interop.Excel.dll file.

Then Use the below code to create a simple excel file and save it to c drive :