nedash says:
using
(XLWorkbook wb =
new
XLWorkbook())
{
wb.Worksheets.Add(dt,
"Customers"
);
Response.Clear();
Response.Buffer =
true
;
Response.Charset =
""
;
Response.ContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
;
Response.AddHeader(
"content-disposition"
,
string
.Format(
"attachment;filename={0}.xls"
, miladitoshamsi(DateTime.Now.ToString(
"yyyy-MM-dd"
))));
using
(MemoryStream MyMemoryStream =
new
MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
Replace the above with the below code.
XLWorkbook wb = new XLWorkbook();
wb.Worksheets.Add(dt, "Customers");
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
//ذخیره فایل به تاریخ
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", DateTime.Now.ToString("yyyy-MM-dd")));
//Response.AddHeader("content-disposition", "attachment;filename=SqlExport.xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
wb.Dispose();
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}