当我想从 Chrome 中导出类型为 IEnumerable 的列表时,它会给我一个错误消息“错误:网络错误”。我在 Firefox 中尝试它,它工作正常,它下载文件。有谁知道如何解决这个问题,或者有替代方法(另一种下载 xls 的方法?)
private void ExportXls(IEnumerable list, string NameFile)
{
var workbook = new Workbook();
workbook.Worksheets.Add(new Worksheet("Datos"));
var worksheet = workbook.Worksheets[0];
var ws = worksheet;
ws.GenerateByIEnumerable(list);
HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.ContentType = "application/octet-stream";
response.AppendHeader("Content-Disposition", "attachment; filename=\"" + NameFile + "_" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx" + "\"");
workbook.Save(response.OutputStream);
response.Flush();
response.Close();
response.End();
}
我能够通过删除并将其
response.Close()
更改为response.ContentType = "application/octet-stream"
来解决它"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
;