1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>excel to json</title> <script src="https://unpkg.com/xlsx@0.18.5"></script> </head>
<body> <input type="file" onchange="toJSON(this)">
<script> function toJSON(obj) { if (!obj.files) { return; }
const file = obj.files[0]; const reader = new FileReader(); reader.onload = function(e) { const excel = XLSX.read(e.target.result, { type: 'binary' }); console.log('excel: ', excel); const json = excel.SheetNames.map(item => { return XLSX.utils.sheet_to_json(excel.Sheets[item]) }) console.log('JSON: ', json); }; reader.readAsBinaryString(file); } </script> </html>
|