0

I have looked through post after posts and cannot figure how to get this to work.

I have a c# controller which i want to return an excel file of the data query from database. My response which I capture from firebug seems to be in binary (see picture) but how do i get the popup asking me to save or open?

thanksenter image description here

public void getData()
        {
            var sql = "select top 10 * from z_main";

            System.Data.DataTable dt = runSQLParamsReturnDT(sql, null, db);
            dt.TableName = "Detail Data";
            using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(dt);
                wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                wb.Style.Font.Bold = true;

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

                using (MemoryStream MyMemoryStream = new MemoryStream())
                {
                    wb.SaveAs(MyMemoryStream);
                    MyMemoryStream.WriteTo(Response.OutputStream);
                    Response.Flush();
                    Response.End();
                }
            }
        }
chungtinhlakho
  • 870
  • 10
  • 21

0 Answers0