我需要将文件导出为excel,但是当我使用此代码执行此操作时,请在此行中返回错误“Exception.SystemOutOfMemory”:wb.Worksheets.Add(dt,“Relatorio”);
using (XLWorkbook wb = new XLWorkbook())
{
string db = Request.QueryString["DB"].ToString().Replace("-", "_");
string de = Request.QueryString["DB"].ToString().Replace("-", "_");
wb.Worksheets.Add(dt, "Relatorio");
wb.Worksheet(1).Range("A1:O1").Style.Fill.BackgroundColor = XLColor.Gainsboro;
wb.Worksheet(1).Range("A1:O1").Style.Font.FontColor = XLColor.DimGray;
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=InventoryReport___" + db + "___" +
de + "___" + DateTime.Now.Day + "_" + DateTime.Now.Month + "_" +
DateTime.Now.Year + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" +
DateTime.Now.Second + ".xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}