尝试从内存流向输出流写入数据表时抛出System.OutOfMemoryException时尝试将Excel文件传递给用户的网页。我使用Closed XML在Excel中保存文件,数据表大约包含40K行和150列,大部分包含小数,导出的文件通常为10MB或更大。在导出到excel的时候,大量数据集被攻破的建议技巧是什么?导出到excel抛出System.OutOfMemoryException
public HttpResponseMessage Get()
{
// Create the workbook
var workbook = new XLWorkbook();
Datatable dt = getDataTable();
workbook.Worksheets.Add(dt);
// Prepare the response
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
var memoryStream = new MemoryStream(); // If I put this in a 'using' construct, I never get the response back in a browser.
workbook.SaveAs(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin); // Seem to have to manually rewind stream before applying it to the content.
response.Content = new StreamContent(memoryStream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "HelloWorld.xlsx" };
return response;
}
您能否发布一些有用的链接来解释Reflation Method? – Anusha