I am trying to export data from database to excel 2007 file.
I just want to change the header of html file to excel 2007 file.
I format the data into a table a
How about just generating a .csv? Why do you need a full-blown native Excel file? Another easy option is to just generate HTML content and then set the output content type to excel. Excel will open it and format it, its a quick shortcut, but it works.
I use this form :
using(System.IO.MemoryStream ms = /*Include Excel File*/) {
ControllerContext.HttpContext.Response.Clear();
ControllerContext.HttpContext.Response.AddHeader("cache-control", "private");
ControllerContext.HttpContext.Response.AddHeader("Content-disposition", "attachment; filename=" + filename + ";");
ControllerContext.HttpContext.Response.AddHeader("Content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
ms.WriteTo(ControllerContext.HttpContext.Response.OutputStream);
}
return null;