标签:buffer put read 通过 sheet from readasa 导入 out
作者:张艳涛
日期:2020-07-29
importfxx(obj) { let _this = this; let inputDOM = this.$refs.inputer; // 通过DOM取文件数据 this.file = event.currentTarget.files[0]; var rABS = false; //是否将文件读取为二进制字符串 var f = this.file; var reader = new FileReader(); //if (!FileReader.prototype.readAsBinaryString) { FileReader.prototype.readAsBinaryString = function(f) { var binary = ""; var rABS = false; //是否将文件读取为二进制字符串 var pt = this; var wb; //读取完成的数据 var outdata; var reader = new FileReader(); reader.onload = function(e) { var bytes = new Uint8Array(reader.result); var length = bytes.byteLength; for(var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); } var XLSX = require(‘xlsx‘); if(rABS) { wb = XLSX.read(btoa(fixdata(binary)), { //手动转化 type: ‘base64‘ }); } else { wb = XLSX.read(binary, { type: ‘binary‘ }); } // outdata就是你想要的东西 excel导入的数据 outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); console.log(‘未处理的原始数据如下:‘); console.log(outdata); // excel 数据再处理 let arr = [] outdata.map(v => { let obj = {} obj.s1 = v[‘员工号‘] obj.s2 = v[‘员工姓名‘] obj.s3 = v[‘员工邮箱‘] obj.s4 = v[‘部门编号‘] obj.s5 = v[‘部门名称‘] obj.s6 = v[‘职位1‘] obj.s7 = v[‘职位2‘] obj.s8 = v[‘上级领导1‘] obj.s9 = v[‘上级领导2‘] arr.push(obj) }) _this.da=arr; _this.dalen=arr.length; console.log("this is a mark for list.vue line 242") console.log( this.accountList); this.zytloading=true; _this.showtable2=true; } reader.readAsArrayBuffer(f); } if(rABS) { reader.readAsArrayBuffer(f); } else { reader.readAsBinaryString(f); } }
标签:buffer put read 通过 sheet from readasa 导入 out
原文地址:https://www.cnblogs.com/zytcomeon/p/13398929.html