1// the simplest way to read excel is to use sheetjs
2// https://github.com/SheetJS/sheetjs
3
4// A. in nodejs
5var XLSX = require('xlsx');
6var workbook = XLSX.readFile('test.xlsx');
7/* DO SOMETHING WITH workbook HERE */
8
9// B. in browser
10// 1. first include the library
11// <script src="dist/xlsx.full.min.js"></script>
12
13// 2. handle the file upload in a script
14
15function handleFile(e) {
16 var files = e.target.files, f = files[0];
17 var reader = new FileReader();
18 reader.onload = function(e) {
19 var data = new Uint8Array(e.target.result);
20 var workbook = XLSX.read(data, {type: 'array'});
21
22 /* DO SOMETHING WITH workbook HERE */
23 };
24 reader.readAsArrayBuffer(f);
25}
26input_dom_element.addEventListener('change', handleFile, false);
27
1<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script>
2<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script>
3<script>
4var ExcelToJSON = function() {
5
6 this.parseExcel = function(file) {
7 var reader = new FileReader();
8
9 reader.onload = function(e) {
10 var data = e.target.result;
11 var workbook = XLSX.read(data, {
12 type: 'binary'
13 });
14
15 workbook.SheetNames.forEach(function(sheetName) {
16 // Here is your object
17 var XL_row_object = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
18 var json_object = JSON.stringify(XL_row_object);
19 console.log(json_object);
20
21 })
22
23 };
24
25 reader.onerror = function(ex) {
26 console.log(ex);
27 };
28
29 reader.readAsBinaryString(file);
30 };
31};
32</script>
33