Download file with ClosedXML

前端 未结 7 2229
走了就别回头了
走了就别回头了 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:16

    If you are using MVC just use the File() method as follows:

    using (XLWorkbook wb = new XLWorkbook())
     {
      //here you put your data in the WorkBook
      //then create a Memory Stream object
    using (MemoryStream stream = new MemoryStream())
      {
       //save the workbook as a MemoryStream
         wb.SaveAs(stream);
    
       //use the File method to return a File
       return File(stream.ToArray(), "filetype","fileName.extension");
       }
     }
    

提交回复
热议问题