首页新闻找找看学习计划

导出excel

0
悬赏园豆:10 [已关闭问题] 关闭于 2016-06-21 13:58

我要做一个导出功能,就是把查询出来的信息以table的格式显示,以HTML格式保存,然后默认它的文件名和后缀为XLS,因为这样打开就是一个表格了

麻辣小螃蟹的主页 麻辣小螃蟹 | 初学一级 | 园豆:173
提问于:2016-06-13 16:02
< >
分享
所有回答(2)
0

http://www.cnblogs.com/itslives-com/p/DownExcel.html

无影飞絮剑 | 园豆:1155 (小虾三级) | 2016-06-13 16:11
0
//这个是创建的一个一般处理器,进入处理器的前提是你url地址是针对的这里才行
///
<summary> /// DownLoad 的摘要说明 /// </summary> public class DownLoad : IHttpHandler { /// <summary> /// 导出会员信息 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { string info = context.Request.QueryString["info"]; MemberMgr bll = new MemberMgr(); context.Response.ContentType = "application/octet-stream"; context.Response.AddHeader("content-disposition", "attachment;filename=会员信息表.xls"); List<Excel_MemberInfo> memlist = bll.ExportMemberInfo(info); StringBuilder sb = new StringBuilder(); context.Response.Write("<table border='1'cellspacing='0' cellpadding='0'>"); context.Response.Write("<tr>"); List<string> list = new List<string> { "序号", "会员卡号", "会员名称", "密码", "手机", "电话", "性别", "身份证", "会员生日", "地址", "邮编", "邮箱", "照片", "有效期", "备注", "所属店铺", "推荐人卡号", "提成人", "余额", "积分", "等级", "会员卡状态", "注册日期", "锁定会员等级", "是否可用", "操作人", "操作时间", "操作IP地址" }; ////第一行 foreach (var item in list) { context.Response.Write("<td style='font-size:14px;text-align:center;'>" + item + "</td>"); } context.Response.Write("</tr>"); //获取的参数列表绑定 foreach (var item in memlist) { context.Response.Write("<tr>"); context.Response.Write("<td>" + item.MemberID + "</td>"); context.Response.Write("<td>" + item.MemberNO + "</td>"); context.Response.Write("<td>" + item.MemberName + "</td>"); context.Response.Write("<td>" + item.Password + "</td>"); context.Response.Write("<td>" + item.MemberPhone + "</td>"); context.Response.Write("<td>" + item.MemberTel + "</td>"); context.Response.Write("<td>" + item.MemberSex + "</td>"); context.Response.Write("<td>" + item.MemberNumber + "</td>"); context.Response.Write("<td>" + item.MemberBirthday + "</td>"); context.Response.Write("<td>" + item.Province + "" + item.City + "" + item.District + "" + item.MemberAddress + "</td>"); context.Response.Write("<td>" + item.MemberZip + "</td>"); context.Response.Write("<td>" + item.MemberEmail + "</td>"); context.Response.Write("<td>" + item.MemberPicture + "</td>"); context.Response.Write("<td>" + item.MemberPeriod + "</td>"); context.Response.Write("<td>" + item.MemberRemarks + "</td>"); context.Response.Write("<td>" + item.CompanyName + "</td>"); context.Response.Write("<td>" + item.MemberReferrerNo + "</td>"); context.Response.Write("<td>" + item.MemberPushMoneyPeople + "</td>"); context.Response.Write("<td>" + item.Balance + "</td>"); context.Response.Write("<td>" + item.Integral + "</td>"); context.Response.Write("<td>" + item.GradeLevelName + "</td>"); context.Response.Write("<td>" + item.Status + "</td>"); context.Response.Write("<td>" + item.MemberDate + "</td>"); context.Response.Write("<td>" + item.Lock + "</td>"); context.Response.Write("<td>" + item.Hide + "</td>"); context.Response.Write("<td>" + item.UserName + "</td>"); context.Response.Write("<td>" + item.OperationDate + "</td>"); context.Response.Write("<td>" + item.OperationIP + "</td>"); context.Response.Write("</tr>"); } context.Response.Write("</table>"); // string str= context.Request.Params["info"]; context.Response.End(); } public bool IsReusable { get { return false; } } }

 

如此低调的男人 | 园豆:840 (小虾三级) | 2016-06-14 14:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册