失败 - 下载EPPlus.dll生成的excel文件时出现网络错误

Rez*_*ini 11 c# asp.net excel epplus

我尝试EPPlus.dll从asp.net c#web表单应用程序下载一个excel文件.但我得到失败 - 网络错误.应该注意的是,提到的错误只发生在chrome中,并且可以在其他浏览器中成功完成作业.

顺便说一句,这个错误不会发生在我的localhost上,它只发生在主服务器上.

如果有人可以解释这个问题的解决方案将是非常有帮助的.

http://www.irandnn.ir/blog/PostId/29/epplus

小智 17

当我使用Response.Clear()和Response.Close()时,我遇到了同样的问题,并且必须避免它们看下面的代码,如下所示.

Response.Buffer = true;
Response.ContentType = mimeType;
Response.AddHeader("Content-Disposition", "attachment; filename=" + nameOfFile);
Response.BinaryWrite(bytes);
Response.End();
Run Code Online (Sandbox Code Playgroud)


小智 8

试试这个:

using (ExcelPackage p = new ExcelPackage())
{
    //Code to fill Excel file with data.


    Byte[] bin = p.GetAsByteArray();

    Response.ClearHeaders();
    Response.ClearContent();
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", Nombre_Del_Libro + ".xlsx"));
    Response.BinaryWrite(bin);
    Response.Flush();
    Response.End();
}   
Run Code Online (Sandbox Code Playgroud)