vue 从excel中复制数据至el-tabel中 excel粘贴数据 el-tabel

需求:从excel复制数据快速粘贴到el-table中

方法:利用vue的 @paste 拿到数据,用processData切割数据

{{ get_thousand_num(scope.row.supplier_trans_fee) }}{{ get_thousand_num(scope.row.supplier_taxes) }}{{ get_thousand_num(scope.row.supplier_other_fee) }}

获取粘贴数据方法: 

processData(clipboardData) {this.pasteArr = [];var data = clipboardData.getData('Text').split('\n');for (var i = 0; i < data.length; i++) {if (!data[i]) {continue;}const bugdetData = data[i].split('\t');this.pasteArr.push(bugdetData);}return this.pasteArr[0]},

将拿到的数据push进表格中 

pasting(e, item) {if (e.clipboardData) {this.isPaste = true;const arr = this.processData(e.clipboardData);const listLength = Object.keys(this.costList[0]);let index = listLength.length; // 记录数组长度let costIndex = 0; // 粘贴数据取值下标listLength.forEach((_item, i) => {if (item === _item) index = iconsole.log(index, i, arr.length - 1)// 记录当前输入框的下标与成本数组做对比if (i >= index && i <= arr.length) {const max = _item === 'supplier_trans_fee' ? 999999 : 99999;if (_item !== 'remark' && _item !== 'total') {if (_item == 'other_fee') {// 其他费用this.costList[0][_item] = isNaN(arr[costIndex]) ? '' : check_num_negative(arr[costIndex], -99999, 99999);} else {this.costList[0][_item] = isNaN(arr[costIndex]) ? '' : check_num(arr[costIndex], 0, max);}costIndex++;}}})}},

vue复制粘贴问题可以参考:http://ivononic.com/57SB


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部