Monday, 28 May 2012

Export excel without installing Excel 2007 in server

The following url used to create a excel file in specified location.
http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm

After storing the excel file in server, it should be transmitted to local.

if (CreateExcelFileOriginal.CreateExcelDocument(dt, location))
  {
       HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", attachment;filename=" + "sample.xlsx");
       HttpContext.Current.Response.ContentType = "application/spl.xlsx";
       HttpContext.Current.Response.Charset = "";
       HttpContext.Current.Response.TransmitFile(location);
       HttpContext.Current.Response.Flush();
       HttpContext.Current.Response.End();
   }

Response.TransmitFile() to explicitly send the file from your ASP.NET application and then add the Content Type and Content-Disposition headers.

No comments:

Post a Comment