This project has moved and is read-only. For the latest updates, please go here.

How to download the generated file?

Mar 14, 2016 at 4:57 PM
How to download the generated file and let the user to save it at any location?
Mar 23, 2016 at 3:36 PM
Edited Mar 23, 2016 at 3:36 PM
You'll have to save your workbook as a memorystream and write it to the HttpResponse. Something like this:
using (XLWorkbook wb = new XLWorkbook())
{
    // create your workbook here "MyWorkBook"

    // then send it to the http response...

    Response.Clear();
    Response.Buffer = true;
    Response.Charset = "";
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx");

    using (MemoryStream ms = new MemoryStream())
    {
        MyWorkBook.SaveAs(ms);
        ms.WriteTo(Response.OutputStream);
        Response.Flush();
        Response.End();
    }
}
Marked as answer by merlyn333 on 4/29/2016 at 6:12 AM
Apr 29, 2016 at 1:44 PM
Edited Apr 29, 2016 at 2:12 PM
Sorry, I just read your message.

That was awesome!

Thanks for your help!

Now it works as expected.