sourcecode

실패 - EPLus.dll에서 만든 Excel 파일을 다운로드할 때 네트워크 오류 발생

copyscript 2023. 11. 5. 14:55
반응형

실패 - EPLus.dll에서 만든 Excel 파일을 다운로드할 때 네트워크 오류 발생

나는 엑셀 파일을 다운받으려고 노력합니다.EPPlus.dllasp.net c# 웹 양식 응용 프로그램에서.실패했습니다. 네트워크 오류입니다.언급된 오류는 크롬에서만 발생하며 다른 브라우저에서도 성공적으로 작업을 수행할 수 있음을 유의해야 합니다.

그런데 이 오류는 내 로컬 호스트에서 발생하지 않고 메인 서버에서만 발생합니다.

누군가가 이 문제에 대한 해결책을 설명해 준다면 매우 도움이 될 것입니다.

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

응답을 사용할 때도 같은 문제가 있었습니다.지우기() 및 응답.닫기()하고 아래와 같은 내 코드를 보기 위해 피해야 했습니다.

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

시도해 보기:

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();
}   

저는 응답을 사용하지 않는 것을 선호합니다.예외를 던지기 때문에 끝()

    protected void DownloadFile(FileInfo downloadFile, string downloadFilename, string downloadContentType)
    {
        Byte[] bin = File.ReadAllBytes(downloadFile.FullName); 

        Response.ClearHeaders();
        Response.ClearContent();
        Response.ContentType = downloadContentType;
        Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", downloadFilename ));
        Response.BinaryWrite(bin);
        Response.Flush();
        Response.SuppressContent = true; 
    }

저도 같은 문제가 있어서 아래 코드로 해결했습니다. filename=\"Name.xlsx\":

Response.Buffer = true;
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("content-disposition", "attachment; filename=\"Name.xlsx\"");
//Writeout the Content  
Response.BinaryWrite(bytes);

문자열 변수 HTML에 있는 html 테이블 코드를 내보냅니다.

나를 위해 작동하는 코드 따라하기

byte[] myFile = Encoding.ASCII.GetBytes(HTML);
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("Content-Type", "application/excel");
        Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0};", "BAGrowthReport.xls"));
        Response.AddHeader("content-length", myFile.Length.ToString()); //Here is the additional header which is required for Chrome.
        Response.BinaryWrite(myFile);
        Response.Flush();
        Response.Close();

언급URL : https://stackoverflow.com/questions/39617706/failed-network-error-when-downloading-excel-file-made-by-epplus-dll

반응형