document.querySelector("input").onchange = function fildfunction() { let reader = new FileReader() reader.readAsBinaryString(this.files[0]); reader.onload = function () { try { workbook = XLSX.read(reader.result, {type: 'binary'}), // 以二进制流方式读取得到整份excel表格对象 persons = []; // 存储获取到的数据 } catch (e) { console.log('文件类型不正确'); return; } // 表格的表格范围,可用于判断表头是否数量是否正确 var fromTo = ''; console.log(workbook); alert("11") // 遍历每张表读取 for (var sheet in workbook.Sheets) { if (workbook.Sheets.hasOwnProperty(sheet)) { fromTo = workbook.Sheets[sheet]['!ref']; console.log(fromTo); persons = persons.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet])); break; // 如果只取第一张表,就取消注释这行 } } console.log(persons); } }
标签:console,log,表格,导入,Sheets,reader,workbook,sheet From: https://www.cnblogs.com/Ma-YuHao/p/17171538.html