小智 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)
| 归档时间: |
|
| 查看次数: |
10008 次 |
| 最近记录: |