let reader = new FileReader(); reader.onload= e => { //获取数据 let data = e.target.result; let workbook = XLSX.read(data, { type: 'array' }) let firstSheetName = workbook.SheetNames[0] let worksheet = workbook.Sheets[firstSheetName] let results = XLSX.utils.sheet_to_json(worksheet, {range: 0}) // 此处获取result及为最后结果 }
reader.readAsArrayBuffer(file.raw)
const reader = new FileReader() reader.onload = e => { const data = e.target.result const workbook = XLSX.read(data, { type: 'array' }) const firstSheetName = workbook.SheetNames[0] const worksheet = workbook.Sheets[firstSheetName] const header = getHeaderRow(worksheet) if (header[0] != '敏感词'){ that.$message({ message: '请使用模板格式导入', type: 'warning' }); that.$refs.el_upload.uploadFiles.splice(file_site,1) } } reader.readAsArrayBuffer(file.raw) getHeaderRow(sheet) { var that = this; const headers = [] const range = XLSX.utils.decode_range(sheet['!ref']) let C const R = range.s.r + 0; /* start in the first row */ for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */ const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]; /* find the cell in the first row */ let hdr = 'UNKNOWN ' + C // <-- replace with your desired default if (cell && cell.t) hdr = XLSX.utils.format_cell(cell) headers.push(hdr) } return headers },