Export to Excel Easily With Export2Excel Utility

It is always painful to use COM components to export data in to excel file.
So if we use COM components or Microsoft Excel Library then there is constraint that where ever the application is running you have MS Office installed on that machine,So it may be costly for corporate level for extra license .
I have developed a DLL using Open XML which can be used without any extra component.

This DLL can be used with WEB as well as WINDOWS projects. This DLL is currently in development phase and I have released version 1.0 for simple excel export. Given below image and example of its output.

 

How to Use

Its very easy to use. Just download the DLL from the link given below and add reference to it in your project and write the below code in the header of your file in which you want to export the data.

C# Code

using DK.ExcelExport;

VB.NET Code

Imports DK.ExcelExport
Using this DLL you can either save the file internally at some location on server or you can directly send to user through response. For Windows based project, excel can be saved at some location and after or it can be also send to user but for that you have write your own code. Let us see an example to export dataset in web based project and send to user for open/save/cancel options.

VB.NET Code

Export2Excel.Dataset4Export = dsStudentDetails
Export2Excel.FileName = "Student Data"
Export2Excel.IsExport2Response = True
Export2Excel.ResponseObject = Me.Response
Export2Excel.Export()

C# Code

Export2Excel.Dataset4Export = dsStudentDetails;
Export2Excel.FileName = "Student Data";
Export2Excel.IsExport2Response = true;
Export2Excel.ResponseObject = this.Response;
Export2Excel.Export();

From the above code, all the tables inside dataset dsStudentDetails will be exported as separate sheet in the excel file and name of the sheet will be same as the table name in the dataset. see below set of images which were exported from the above code for the dataset having 2 data tables.


Use below code to save file to a particular path in web based project

VB.NET Code

Export2Excel.Dataset4Export = dsStudentDetails
Export2Excel.FileName = "Student Data"
Export2Excel.IsExport2Response = False
Export2Excel.Path2Export = Server.MapPath("~\Data\Files\")
Export2Excel.ResponseObject = Nothing
Export2Excel.Export()

C# Code

Export2Excel.Dataset4Export = dsStudentDetails;
Export2Excel.FileName = "Student Data";
Export2Excel.IsExport2Response = false;
Export2Excel.Path2Export = Server.MapPath("~\Data\Files\");
Export2Excel.ResponseObject = null;
Export2Excel.Export();
Same code can be used in windows based projects. You need to use the code for exporting in to file as there are no response objects in windows based project. Download the DLL from the below link Download Image
Please feel free to mail your experiences/suggestions at admin@dkumar.co.in . It will really help to upgrade and add new functionality in the DLL

Comments