js导出excel功能
<div class="chaxun_btn" v-on:click="daochu(1)" style="cursor: pointer; display: inline-block; margin-left: 30px">导出</div>
daochu: function (c) { /// <summary> /// 付款导出 /// </summary> /// <param name="UserID"></param> /// <param name="StrJson"></param> /// <param name="pageNo"></param> /// <param name="pageSize"></param> /// <param name="fileType"></param> /// <param name="bytes"></param> /// <returns></returns> //public string PaymentMaster_GetPaymentMasterListExcel(string UserID, string StrJson, int pageNo, int pageSize, int fileType, out byte[] bytes) this.daochuexp(1); }, daochuexp: function (c) { //取搜索条件的值 var PaymentMaster_No = $("#Payment_fukuandanhao").val();//付款单号 var Customer_ID = $("#cusId").val();//供应商id var Business_SubMan = $("#guwenId").val();//服务顾问???????????????? var Date_Start = $("#fukuan_riqi_inp1").val();//开始日期 var Date_End = $("#fukuan_riqi_inp2").val();//结束日期 var Status = $("#Payment_zhuangtai").val();//支付状态 var Payment_Type = $("#Payment_zhifu").val();//支付方式 var Audit_SubUser = '';//审核人 //console.log(PaymentMaster_No,Customer_ID,Business_SubMan,Date_Start,Date_End,Status,Payment_Type,Audit_SubUser) if (c == 1) { this.i = 1 } var all = $("#daochunum").val();//得到隐藏域中存储的当前查询出来的总条数 if (all == 0) { $.dialog.alert("列表无数据"); return false; } var count = Number(all) / 60000; var count1 = Math.ceil(count); if (this.timei2 == 0) { this.timei2 = 1; setTimeout(this.daochuexp(), 1000); } else { //延时S秒后执行的语句 if (this.i <= count1) { var ps = 60000; window.open("/Collection/PaymentMaster_GetPaymentMasterListExcel?PaymentMaster_No=" + PaymentMaster_No + "&Customer_ID=" + Customer_ID + "&Business_SubMan=" + Business_SubMan + "&Date_Start=" + Date_Start + "&Date_End=" + Date_End + "&Status=" + Status + "&Payment_Type=" + Payment_Type + "&Audit_SubUser=" + Audit_SubUser + "&pageNo=" + this.i + "&pageSize=" + ps, "exportxls", null); this.timei2 = 0; this.i++; setTimeout(this.daochuexp(), 30000); } else { this.retdao = 0 } } },
//导出明细 public void PaymentMaster_GetPaymentMasterListExcel(string PaymentMaster_No, string Customer_ID, string Business_SubMan, string Date_Start, string Date_End, string Status, string Payment_Type, string Audit_SubUser, int pageNo, int pageSize) { JsonResponse<string> jsonResponse = new JsonResponse<string>(); try { string StrJson = ""; PaymentMaster_Search entity = new PaymentMaster_Search(); entity.PaymentMaster_No = PaymentMaster_No;//付款单号 entity.UserID = user.User_ID;// entity.Customer_ID = Customer_ID;//供应商id entity.Business_SubMan = Business_SubMan;//服务顾问 entity.Date_Start = Date_Start;//开始日期 entity.Date_End = Date_End;//结束日期 entity.Status = Status;//支付状态 entity.Payment_Type = Payment_Type;//支付方式 entity.Audit_SubUser = Audit_SubUser;//审核人 StrJson = JsonConvert.SerializeObject(entity); byte[] data; string json=string.Empty; /********Token验证********/ using (System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope(service.InnerChannel)) { System.ServiceModel.Channels.MessageHeader headerToken = System.ServiceModel.Channels.MessageHeader.CreateHeader("token", "http://*****", user.Token); OperationContext.Current.OutgoingMessageHeaders.Add(headerToken); json = service.PaymentMaster_GetPaymentMasterListExcel(user.User_ID, StrJson, pageNo, pageSize, 1, out data); } Response.Clear(); Response.ClearHeaders(); Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("财务付款" + "_" + Date_Start + "-" + Date_End + "yyyyMMddHHmmssms") + ".xlsx"); Response.BinaryWrite(data); } catch { jsonResponse.status.code = 0; jsonResponse.status.msg = "系统异常"; } }
通过js获取搜索条件的值,放到window.open问号传参给后台的方法,到数据库里查询到所需要的数据,返回给前台的下载功能