public void ImportExcel(string fileName, ExcelEdit exelTools) { exelTools.deleteTempExcel(); FileInfo info = new FileInfo(fileName); base.Response.Charset = "GB2312"; base.Response.ContentEncoding =System.Text.Encoding.UTF8; base.Response.AddHeader("Content-Disposition", "attachment; filename=" + base.Server.UrlEncode(info.Name)); base.Response.AddHeader("Content-Length", info.Length.ToString()); base.Response.ContentType = "application/ms-excel"; base.Response.WriteFile(info.FullName); base.Response.Flush(); info.Delete(); base.Response.End(); }
public void ImportExcel(string fileName, ExcelEdit exelTools) { exelTools.deleteTempExcel(); System.IO.FileInfo file = new System.IO.FileInfo(fileName); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端 Response.WriteFile(file.FullName); // 停止页面的执行 Response.Flush(); file.Delete(); Response.End(); }
protected void ExcelBt_Click(object sender, EventArgs e) { MemberSeachCondition searchCondition = (Session["MemberSerachCondition"] as MemberSeachCondition); MemberManageBLL memberBLL = new MemberManageBLL(); Page<MemberBaseInfo> memberPageInfo = new Page<MemberBaseInfo>(); memberPageInfo = memberBLL.GetMemberList(true, searchCondition); List<MemberBaseInfo> list = new List<MemberBaseInfo>(); if (memberPageInfo != null && memberPageInfo.Data != null) { list = memberPageInfo.Data.ToList<MemberBaseInfo>(); } if (list != null && list.Count > 0) { ExcelEdit edit = new ExcelEdit(); edit.CreateExcel(); edit.WriteHisData(list, 0, list.Count - 1); Random rand = new Random(); string fileName = Server.MapPath(".") + "/MemberList_" + rand.Next(1000).ToString() + ".xls"; edit.ExplortExcel(fileName); ImportExcel(fileName, edit); } }
protected void ExcelBt_Click(object sender, EventArgs e) { ActivitySerachCondition searchCondition = this.Session["ActivitySerachCondition"] as ActivitySerachCondition; ActivityBLL ybll = new ActivityBLL(); Page<ActivityInvo> page = new Page<ActivityInvo>(); page = ybll.GetActivityList(searchCondition, 0, true); List<ActivityInvo> list = new List<ActivityInvo>(); if ((page != null) && (page.Data != null)) { list = page.Data.ToList<ActivityInvo>(); } if ((list != null) && (list.Count > 0)) { ExcelEdit exelTools = new ExcelEdit(); exelTools.CreateExcel(); exelTools.WriteActivityList(list, 0, list.Count - 1); Random random = new Random(); string fileName = base.Server.MapPath(".") + "/ActivityList_" + random.Next(1000).ToString() + ".xls"; exelTools.ExplortExcel(fileName); this.ImportExcel(fileName, exelTools); } }
protected void ExcelBt_Click(object sender, EventArgs e) { List<MemberActivityInfo> list = new List<MemberActivityInfo>(); list = this.Session["MemberActivityList"] as List<MemberActivityInfo>; if ((list != null) && (list.Count > 0)) { ExcelEdit exelTools = new ExcelEdit(); exelTools.CreateExcel(); exelTools.WriteAtivityMember(list, 0, list.Count - 1); Random random = new Random(); string fileName = base.Server.MapPath(".") + "/ActivityMember_" + random.Next(1000).ToString() + ".xls"; exelTools.ExplortExcel(fileName); this.ImportExcel(fileName, exelTools); } }