protected void Btn_MSExport_Click(object sender, EventArgs e)
{
DataSet ds = getDataSetExportToExcel();
ds.Tables[0].TableName = "Customers";
ds.Tables[1].TableName = "Employees";
using (XLWorkbook
wb = new XLWorkbook())
{
wb.Worksheets.Add(ds);
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=
EmployeeAndOrderReport.xlsx");
using (MemoryStream
MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
No comments:
Post a Comment