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

July 18th, 2012 by admin Leave a reply »

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

Response.ContentType = “application/”;
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



Leave a Reply