import XLSX from “xlsx”;
<input type="file" id="uploadFile" value="上传文件">
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);
},