vue js 读取.csv .xls 类型文件
Posted 几许风雨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue js 读取.csv .xls 类型文件相关的知识,希望对你有一定的参考价值。
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 },
以上是关于vue js 读取.csv .xls 类型文件的主要内容,如果未能解决你的问题,请参考以下文章
文件上传(支持csv,xls,xlsx,txt格式)把文件导入到minio,还需要生成一个demo临时文件只放10条数据
文件上传(支持csv,xls,xlsx,txt格式)把文件导入到minio,还需要生成一个demo临时文件只放10条数据