MVC | .NET |在MS Excel中打开时Excel导出无响应

时间:2018-02-28 05:55:44

标签: excel asp.net-mvc-4 export-to-excel

从视图中对一个excel文件进​​行Genterate,如果文件的数据内容较少,则工作正常,但是当文件大小变大时,文件在MS-Exce中没有响应。当我试图打开它时,一条消息显示出来:

file is croupted or unsafe

如果我单击是打开,则在花费很多时间加载后无法响应。

用于生成excel的代码:

Response.Clear();
                Response.ClearHeaders();
                Response.ContentType = "application/ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xls\"");
                Response.Write("<html xmlns:x='urn:schemas-microsoft-com:office:excel'>");
                return View(data);

此外,我还尝试了不同的ContentType和Extension选项,但没有得到结果:

ContentType                         Extension       Result
application/ms-excel                .xls             No(Same issue)
application/vnd.ms-excel            .xls             No(Same issue)
application/ms-excel                .xlsx            No(Same issue)
application/vnd.ms-excel            .xlsx            No(Same issue)
application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet  .xlsx            file opened a blank sheet

0 个答案:

没有答案
相关问题