1//import it
2
3 import * as XLSX from 'ts-xlsx';
4
5//inside export class
6
7arrayBuffer:any;
8file:File;
9incomingfile(event)
10 {
11 this.file= event.target.files[0];
12 }
13
14 Upload() {
15 let fileReader = new FileReader();
16 fileReader.onload = (e) => {
17 this.arrayBuffer = fileReader.result;
18 var data = new Uint8Array(this.arrayBuffer);
19 var arr = new Array();
20 for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
21 var bstr = arr.join("");
22 var workbook = XLSX.read(bstr, {type:"binary"});
23 var first_sheet_name = workbook.SheetNames[0];
24 var worksheet = workbook.Sheets[first_sheet_name];
25 console.log(XLSX.utils.sheet_to_json(worksheet,{raw:true}));
26 }
27 fileReader.readAsArrayBuffer(this.file);
28}