大家好,又见面了,我是你们的朋友全栈君。
废话不多说,直接上代码
public void ExportExcel()
{
string datefrom = Request.QueryString["datefrom"];
string dateto = Request.QueryString["dateto"];
string ID = Request.QueryString["ID"];
Report_AgentModel model = new Report_AgentModel();
string strSql = model.getExcelSql(datefrom, dateto, ID);
string sort = "createtime desc";
string sheetName = "Report_Agent";
ExcelHelper help = new ExcelHelper();
ExcelHelper.NpoiMemoryStream ms = help.ExportExcel(sheetName, strSql, sort);
//输出Excel
string filename = "Report_Agent_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Length", ms.Length.ToString());
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", Server.UrlEncode(filename)));
Response.BinaryWrite(ms.GetBuffer());
Response.Flush();
Response.End();
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/151689.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...