how to export asp.net MVC detail view data to an excel file?

前端 未结 3 1726
轻奢々
轻奢々 2021-01-16 16:47

How to export ASP.NET MVC view data to an excel file ? Actually my view page contain many viewdata types. I am using for each loop with these datatype to displaying data on

3条回答
  •  深忆病人
    2021-01-16 16:56

    Depending on the complexity of the page's HTML you might be able to get away with just changing the header type to application/excel. Excel has built in html parsing functionality. I've successfully done this many times a few years back with a DataGrid on a page.

    Response.ContentType = "application/excel"
    Response.AppendHeader "content-disposition", "attachment: filename=TestExcelFile.xls"
    

    Some details on HTML in excel

提交回复
热议问题