I am manipulating Excel files using javascript, I am converting the file into a json object then looping for each row . I am using this code
document.getElementById('confirm').addEventListener("click", () => {
XLSX.utils.json_to_sheet(data, 'out.xlsx');
if (selectedfile && etat == 0) {
let fileReader = new FileReader();
fileReader.readAsBinaryString(selectedfile);
fileReader.onload = (event) => {
etat++;
let data = event.target.result;
let workbook = XLSX.read(data, { type: "binary" });
console.log(workbook);
workbook.SheetNames.forEach(sheet => {
let rowObject = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheet],{raw: false});
let ok = JSON.stringify(rowObject, undefined, 4);
let tab = JSON.parse(ok);
let num = tab.length;
console.log(parseInt(num/1000));
for(j = 0;j<parseInt(num/1000)+1;j++){
let row = j *1000;
let ligne;
if(j == num)
ligne = num;
else
ligne = (j+1)* 1000;
let table = [];
for(i = row; i<ligne; i++){
let jour = tab[i].JOUR;
let date = tab[i].DATE;
let compte = tab[i].COMPTE;
let code = tab[i].CODE;
let libelles = tab[i].LIBELLES;
let debit = tab[i].DEBIT ;
let creadit = tab[i].CREDIT;
let ech = tab[i].ECH;
let LETT = tab[i].LETT;
table.push( [jour , date,compte , code , libelles , debit , creadit , ech , LETT] );
console.log(i);
}
}
/**/
});
}
}
}
);
The excel file contains more than 17k rows, this code takes too much time ( over 15 mins ) and causes crashes.