1.官方地址:/SheetJS/js-xlsx
2.HTML代码:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><script src="jquery.js" charset="utf-8"></script><script src="xlsx.core.min.js" type="text/javascript" charset="utf-8"></script></head><body><input type="file" id="excel"><script type="text/javascript">$('#excel').change(function(e) {var files = e.target.files;var fileReader = new FileReader();fileReader.onload = function(ev) {try {var data = ev.target.resultvar workbook = XLSX.read(data, {// 以二进制流方式读取得到整份excel表格对象type: 'binary'})var persons = []; // 存储获取到的数据} catch (e) {return;}var fromTo = '';// 遍历每张表读取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);};// 以二进制方式打开文件fileReader.readAsBinaryString(files[0]);});</script></body></html>
3.xlsx.core.min.js
详看我的资源进行下载。