I'm trying to export my Asp.net core Grid content to excel format.
The samples that are available don't work because Response.OutputStream is not accessible in ASP.Net Core, so i've tried this:
private void SendForDownload(Workbook document, WorkbookFormat excelFormat) { string documentFileNameRoot; documentFileNameRoot = string.Format("Document.{0}", excelFormat == WorkbookFormat.Excel97To2003 ? "xls" : "xlsx");
Response.Clear(); Response.Headers.Add("content-disposition", "attachment; filename=" + documentFileNameRoot); Response.ContentType = "application/octet-stream"; document.SetCurrentFormat(excelFormat); document.Save(Response.Body);
base.File(Response.Body, "application/octet-stream"); }
However, it's not creating the file for download. Has anyone accomplished this in Asp.Net Core?
The Workbook is being populated properly, just nothing happens when it attempts the save.
Hello Andrew,
Thank you for posting into our community!
I have been looking into your question and I assume you are referring to our Create Excel Worksheet sample here.
Having this in mind, in an effort to reproduce the described behavior, I have prepared a small sample in a similar manner to the abovementioned one. In the SendForDownload method, I have used a similar configuration to the one provided by you, however, on my side, when clicking the "Export" button, the Excel file is populated and downloaded successfully.
This could be observed in the below attachment:
Attached could be found my sample for your reference. Please test it on your side and let me know how it behaves.
Looking forward to your reply.
Sincerely, Riva Ivanova Associate Software Developer
8863.Export To Excel MVC.zip