....
import * as XLSX from 'xlsx';
...
I am currently parsing a .xlsx file in an Ionic 4 application.
showData() {
let fileReader = new FileReader();
fileReader.onloadend = (e) => {
this.arrayBuffer = fileReader.result;
let data = new Uint8Array(this.arrayBuffer);
let arr = new Array();
for (let i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
let bstr = arr.join("");
let workbook = XLSX.read(bstr, { type: "binary" });
let first_sheet_name = workbook.SheetNames[0];
let worksheet = workbook.Sheets[first_sheet_name];
let rows = XLSX.utils.sheet_to_json<Income>(worksheet, { raw: true });
this.allIncomesFromDocument = rows
this.Test(rows)
}
fileReader.readAsArrayBuffer(this.file);
}
Test(rows){
this.allIncomesFromDocument.forEach( v => console.log(v.quantity) ) // FIRST LOG
rows.forEach( row =>{
row.quantity = 0;
})
this.allIncomesFromDocument.forEach( v => console.log(v.quantity) ) // SECCOND LOG
}
The first log displays the following data:
8
7
5
9
2
etc.
This reflects the information extracted from the file initially.
However, despite not changing any values and simply repeating the same forEach loop, the second log instead shows:
0
0
0
etc.
Clearly indicating that the logs are entirely divergent.