从视图中对一个excel文件进行Genterate,如果文件的数据内容较少,则工作正常,但是当文件大小变大时,文件在MS-Exce中没有响应。当我试图打开它时,一条消息显示出来:
如果我单击是打开,则在花费很多时间加载后无法响应。
用于生成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