import XLSX from “xlsx”;

    1. <input type="file" id="uploadFile" value="上传文件">
    1. checkSheet() {
    2. const objFile = document.getElementById('uploadFile')
    3. if (objFile.value === '') {
    4. alert('请选择文件!')
    5. return
    6. }
    7. // 获取文件
    8. const files = objFile.files
    9. const _that = this
    10. const fileReader = new FileReader();
    11. fileReader.onload = function(ev) {
    12. console.log('ev: ', ev);
    13. const data = ev.target.result,
    14. workbook = XLSX.read(data, {
    15. type: 'binary'
    16. })
    17. let dataList = [];
    18. // 遍历每张表读取
    19. console.log('workbook: ', workbook);
    20. for (var sheet in workbook.Sheets) {
    21. if (workbook.Sheets.hasOwnProperty(sheet) && sheet === 'device') {
    22. dataList = dataList.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
    23. console.log('sheet: ', sheet);
    24. }
    25. }
    26. _that.analysisSheet(dataList)
    27. };
    28. fileReader.readAsBinaryString(files[0]);
    29. },
    30. analysisSheet(data) {
    31. console.log('data: ', data);
    32. },

    image.png
    image.png