Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  51] [ 2]  / answers: 1 / hits: 19680  / 5 Years ago, fri, september 6, 2019, 12:00:00

I have my Angular-CLI frontend development server running locally on localhost:4200



I need to get a local Excel file stored on my PC, read its content and
make some calls to an API from the client side.



I'm trying to use js-xlsx, got it installed with npm install xlsx but I can't find how to get the file and read its content.


How can I import a local excel file with js-xlsx in Angular 13?


More From » excel

 Answers
8

Here is working Example



onFileChange(ev) {
let workBook = null;
let jsonData = null;
const reader = new FileReader();
const file = ev.target.files[0];
reader.onload = (event) => {
const data = reader.result;
workBook = XLSX.read(data, { type: 'binary' });
jsonData = workBook.SheetNames.reduce((initial, name) => {
const sheet = workBook.Sheets[name];
initial[name] = XLSX.utils.sheet_to_json(sheet);
return initial;
}, {});
const dataString = JSON.stringify(jsonData);
document.getElementById('output').innerHTML = dataString.slice(0, 300).concat(...);
this.setDownload(dataString);
}
reader.readAsBinaryString(file);
}

[#51685] Thursday, August 29, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;