This might be helpfull for you....
protected void GenerateExcel(DataTable dta)
{
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dta, "Sheet1");
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=EmploymentTracker.xls");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
Please mark this as answer if this helps... :)