Writing Excel using EPPLUS not workable after depl

2019-08-01 07:19发布

问题:

I'm using EPPlus to generate excel (.xlsx) in my mvc3 web application. It works fine with my localhost. However, after i deployed to the server, the excel file return as an Excel Binary Workbook. Can anyone help me?

Here is how i generate my excel (.xlsx):

    ExcelPackage pck = new ExcelPackage();
    ExcelWorksheet ew = pck.Workbook.Worksheets.Add("template" + templateVM.Year);

    List<YieldsTemplate> list = mgr.GetTemplates(templateVM.Year);

    ew.Cells["A1"].LoadFromCollection(list, true);
    ew.Cells["A:AZ"].AutoFitColumns();

    Response.Clear();
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment: filename=" + "abc" + ".xlsx");
    Response.BinaryWrite(pck.GetAsByteArray());
    Response.End();

thank you!!