js 获取 excel 内容实现
导入 xlsx
import XLSX from "xlsx";
选择 excel 文件
读取 excel 文件内容
checkSheet() { const objFile = document.getElementById('uploadFile') if (objFile.value === '') { alert('请选择文件!') return } // 获取文件 const files = objFile.files const _that = this const fileReader = new FileReader(); fileReader.onload = function(ev) { console.log('ev: ', ev); const data = ev.target.result, workbook = XLSX.read(data, { type: 'binary' }) let dataList = []; // 遍历每张表读取 console.log('workbook: ', workbook); for (var sheet in workbook.Sheets) { if (workbook.Sheets.hasOwnProperty(sheet) && sheet === 'device') { dataList = dataList.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet])); console.log('sheet: ', sheet); } } _that.analysisSheet(dataList) }; fileReader.readAsBinaryString(files[0]); }, analysisSheet(data) { console.log('data: ', data); },