Layui第三方扩展LAY_EXCEL导出自己想要的列的数据表格

由于后端返回了一些不必要的字段,如果直接用Layui第三方扩展导出,那些字段就会自己显示出来,有点影响美观所以前端需要过滤一下
html代码一个导出的按钮

<button class="layui-btn" id="ExportExcel">导出Excel</button>

js代码

		//导出Excel按钮
	    var  excel=LAY_EXCEL;//就是怎么写不要多想
		$('#ExportExcel').on('click', function() {
			$.ajax({
				url: 'http://localhost:65290/api/ProduceTransfer/GetAllProduceTransferExcel',
				type: "post",
				headers: {
					'access_token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					data = excel.filterExportData(data, {//这里写你要显示的字段
				   	id:"id"
	                ,code:"code"
	                ,produce_code:"produce_code"
	                ,po:"po"
	                ,supplier_fast_code:"supplier_fast_code"
					,supplier_short_name:"supplier_short_name"
					,produce_name:"produce_name"
					,valuation_count:"valuation_count"
					,delivery_quantity_count:"delivery_quantity_count"
					,acceptance_quantity_count:"acceptance_quantity_count"
					,gram_weight:"gram_weight"
					,material_name:"material_name"
					,flute:"flute"
					,material_category:"material_category"
					,produce_length:"produce_length"
					,produce_width:"produce_width"
					,valuation_price:"valuation_price"
					,valuation_amount:"valuation_amount"
					,valuation_unit:"valuation_unit"
					,purchase_count:"purchase_count"
					,purchase_unit:"purchase_unit"
					,remark:"remark"
					});
                    data.unshift({//相对应的列名
						"id": "编号",
						"code": "原材料编号",
						"produce_code": "生产编号",
						"po": "PO编号",
						"supplier_fast_code":"供应商代码",
						"supplier_short_name":"供应商简称",
						"produce_name": "订单名称",
						"valuation_count": "数量",
						"delivery_quantity_count": "已发货数量",
						"acceptance_quantity_count": "验收数量",
						"gram_weight": "克重",
						"material_name":"原料名称",
						"flute": "楞型",
						"material_category": "原料类别",
						"produce_length": "长",
						"produce_width": "宽",
						"valuation_price": "单价",
						"valuation_amount": "金额",
						"valuation_unit": "计价单位",
						"purchase_count": "采购数量",
						"purchase_unit": "采购单位",
						"remark": "备注"
					});
					LAY_EXCEL.exportExcel(data, '导出Excel数据.xlsx', 'xlsx');
				}
			})
		})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值