Need an easy and clean way to export your asp.net data to Excel?

July 18th, 2012 by admin Leave a reply »

If you are doing any research on how to get data contained in asp.net pages out to excel, the first path you may take, like i did was to set the Response, something like this:

Response.ContentType = “application/vnd.ms-excel”;
Response.AddHeader(“content-disposition”,”attachment; filename=BizImportReport.xls”);

Well, this was producing for me an excel file with all of the response in it which included the entire webpage, and no matter how many different ways I tried to get the data into some kind of form that would export well, it never worked, until I came across a little library that does exactly what I want in a couple lines of code, so it looks something like this:

var objExport = new Export(“Web”);
if (DS.Tables[0].Rows.Count > 0)
objExport.ExportDetails(DS.Tables[0], Export.ExportFormat.Excel, “yourexcelfile.xls”);

Here is the link to this library, enjoy  Excel Export Library

 

Advertisement

Leave a Reply