页面导出csv/excel

function capitalEstimateExport(){
	$.post(BASE_PATH+'report/preFeeList', {houseStatus:$('#houseStatus').val(), houseName:$('#houseName').val(),timeFromStr:$('#timeFromStr').val(),timeToStr:$('#timeToStr').val()}, function(data){
		if(data.records.length > 0){
			debugger
			var dlist = data.records;
	        var obj = {title:"", titleForKey:"", data:""};
	        obj.title = ["房源编号","房源名字","房源小区","房源地址(路、弄、号、室)","预计付款","实际付款","是否需交租","预计收租","实际收租","是否需收租"];
	 		obj.titleForKey = ["houseNo","houseName","houseEstate","houseAddress","willPay","actPay","payIsOverdue","willRent","actRent","rentIsOverdue"];
			obj.data = dlist;
            exportCsv(obj);
		} else{
			alert("没有数据,无法导出!");
		}
	});
}
function exportCsv(obj){
     var title = obj.title;
     var titleForKey = obj.titleForKey;
     var data = obj.data;
     var str = [];
     str.push(obj.title.join(",")+"\n");
     for(var i=0;i<data.length;i++){
         var temp = [];
         for(var j=0;j<titleForKey.length;j++){
             temp.push(data[i][titleForKey[j]]);
      }
      str.push(temp.join(",")+"\n");
  }
  var uri = 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent(str.join(""));  
  var downloadLink = document.createElement("a");
  downloadLink.href = uri;
  downloadLink.download = "资金预估报表.csv"; 
  document.body.appendChild(downloadLink);
  downloadLink.click();
  document.body.removeChild(downloadLink); 
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值