I am not able to get data from an Excel sheet in Angular 4. Below is my code sample.
HTML code:
readfile() {
// You can change the file path in the assets folder
let url = "/assets/template.xlsx";
let req = new XMLHttpRequest();
req.open("GET", url, true);
req.responseType = "arraybuffer";
req.onload = (e) => {
let data = new Uint8Array(req.response);
let workbook = XLSX.read(data, {type: "array"});
const excelBuffer: any = XLSX.write(workbook, {bookType: 'xlsx', type: 'array'});
// TO export the excel file
this.saveAsExcelFile(excelBuffer, 'X');
};
req.send();
}
You can take this code and change the path to your file; for the last line is for export it. To know more about it i suggest to visit the official doc of js-xlsx https://github.com/SheetJS/js-xlsx