Download Excel file via AJAX MVC

后端 未结 14 1774
说谎
说谎 2020-11-22 02:30

I have a large(ish) form in MVC.

I need to be able to generate an excel file containing data from a subset of that form.

The tricky bit is that this shouldn

14条回答
  •  [愿得一人]
    2020-11-22 03:11

    $.ajax({
                    type: "GET",
                    url: "/Home/Downloadexcel/",
                    contentType: "application/json; charset=utf-8",
                    data: null,
                    success: function (Rdata) {
                        debugger;
                        var bytes = new Uint8Array(Rdata.FileContents); 
                        var blob = new Blob([bytes], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
                        var link = document.createElement('a');
                        link.href = window.URL.createObjectURL(blob);
                        link.download = "myFileName.xlsx";
                        link.click();
                    },
                    error: function (err) {
    
                    }
    
                });
    

提交回复
热议问题