MVC3 C# Export to Excel

前端 未结 2 1403
傲寒
傲寒 2021-01-26 08:15

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

2条回答
  •  醉梦人生
    2021-01-26 08:56

    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;
    

提交回复
热议问题