Download file with ClosedXML

前端 未结 7 2193
走了就别回头了
走了就别回头了 2020-12-03 04:46

All

How can I download a file so the user sees that it is downloading (like with a stream?)

I am currently using ClosedXML, but if I use the SaveAs method, I

7条回答
  •  死守一世寂寞
    2020-12-03 05:15

    public ActionResult SendFile()
    {
        // Create the workbook
        XLWorkbook workbook = new XLWorkbook();
        workbook.Worksheets.Add("Sample").Cell(1, 1).SetValue("Hello World");
    
        // Send the file
        MemoryStream excelStream = new MemoryStream();
        workbook.SaveAs(excelStream);
        excelStream.Position = 0;
        return File(excelStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "MyFileName.xlsx");
    }
    

提交回复
热议问题