Currently, I am in the process of uploading an excel file that contains an ID column as its first column.
My goal is to extract all the IDs and store them in an array for future data management purposes.
To accomplish this task, I am utilizing the XLSX
library:
import {read, write, utils} from 'xlsx';
For the HTML part of the code:
<input type="file" value="Upload Excel/CSV file" (change)="upload($event)" accept=".xlsx, .xls, .csv"/>
<button mat-fab color="warn" (click)="read()"><mat-icon color="warn">attach_file</mat-icon>Read Data</button>
I have initiated the process with:
read()
{
const file = new FileReader();
}
However, I am encountering difficulties instructing the file reader to read the uploaded file.
UPDATE
In an attempt to address this issue, I experimented with the change event associated with the file input:
upload(e)
{
let input = e.target;
for (var index = 0; index < input.files.length; index++) {
let reader = new FileReader();
reader.onload = () => {
// The 'text' variable stores the content of the file
var text = reader.result;
console.log(reader.result)
}
reader.readAsText(input.files[index]);
};
}
Unfortunately, the output from the read operation appears to be encrypted.