Send query results to Excel from ASP.NET website

后端 未结 7 1061
失恋的感觉
失恋的感觉 2020-12-17 03:03

We let users create ad-hoc queries in our website. We would like to have the user select their criteria, then click submit and have the results streamed automatically to Ex

7条回答
  •  醉梦人生
    2020-12-17 03:25

    If you create a page that is just a table with the results and set the page's content type to "application/vnd.ms-excel", then the output will be in Excel.

    Response.ContentType = "application/vnd.ms-excel";
    

    If you want to force a save, you would do something like the following:

    Response.AddHeader("Content-Disposition", "attachment; filename=somefilename.xls");
    

提交回复
热议问题