函数下方将Excel工作表(XLSX格式)数据转换为JSON。您可以向函数添加promise。
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script><script>var ExcelToJSON = function() { this.parseExcel = function(file) { var reader = new FileReader(); reader.onload = function(e) { var data = e.target.result; var workbook = XLSX.read(data, { type: 'binary' }); workbook.SheetNames.forEach(function(sheetName) { // Here is your object var XL_row_object = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]); var json_object = JSON.stringify(XL_row_object); console.log(json_object); }) }; reader.onerror = function(ex) { console.log(ex); }; reader.readAsBinaryString(file); };};</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)