protected void Page_Load(object sender, EventArgs e) { base.AllowHttpMethod("POST"); var user = AuthServer.GetLoginUser(); var dt = MSDB.GetDataTable("ConnDB", "dbo.usp_RecordM_xGetSchoolCodeByOrgID" , new Dictionary <string, object>() { { "@OrgID", user.OrgID } }); Response.ContentType = "application/download"; Response.AddHeader("Content-Disposition", string.Format("attachment; filename=" + HttpUtility.UrlEncode("範本-學校代碼.xls"))); ExcelToolT tool = new ExcelToolT(); tool.RenderDataTableToExcel(dt).CopyTo(Response.OutputStream); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { //base.AllowHttpMethod("POST"); string BirthDateS; string BirthDateE; int SearchKind = 1; int OrgID = 0; BirthDateS = Request.Form["BirthDateS"] ?? ""; BirthDateE = Request.Form["BirthDateE"] ?? ""; if (BirthDateS != "") { BirthDateS = TaiwanYear.ToDateString(BirthDateS); } if (BirthDateE != "") { BirthDateE = TaiwanYear.ToDateString(BirthDateE); } int.TryParse(Request["SearchKind"], out SearchKind); int.TryParse(Request["OrgID"], out OrgID); DataTable dt = (DataTable)DBUtil.DBOp("ConnDB", " exec dbo.usp_CaseUser_xGetMergeUserListToExport {0},{1},{2},{3} " , new string[] { BirthDateS, BirthDateE, OrgID.ToString(), SearchKind.ToString() }, NSDBUtil.CmdOpType.ExecuteReaderReturnDataTable); //DataTableToCSV.DownloadCSV(dt, "MyCsv.csv"); ExcelToolT t = new ExcelToolT(); Response.Clear(); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/download"; Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode("99未歸戶個案維護.csv")); Response.BinaryWrite(((MemoryStream)t.RenderDataTableToExcel(dt)).ToArray()); Response.End(); }