Trying to incorporate the xlsx
angular library to bring in an excel file onto my page:
Following some instructions from the xlsx library documentation, I created this function:
public async HandleExcelFile(excelFile)
{
//Initialize empty Excel Array
let excelData : Array<any> = [];
let error : any = null;
return new Promise<Object>((resolve, reject) =>
{
var file = document.getElementById(excelFile)
const inputFile: DataTransfer = <DataTransfer>(excelFile.target);
const fileReader: FileReader = new FileReader();
fileReader.onload = (event: any) =>
{
const binaryString: string = event.target.result;
const workBook: XLSX.WorkBook = XLSX.read(binaryString, { type: 'binary', sheetStubs: true});
const workSheetName: string = workBook.SheetNames[0];
const workSheet: XLSX.WorkSheet = workBook.Sheets[workSheetName];
excelData = <aoa>(XLSX.utils.sheet_to_json(workSheet,
{header: 1, blankrows: true }));
};
fileReader.readAsBinaryString(inputFile.files[0]);
But when I try to upload the file using an html input, I encounter this error message:
Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'excelFile.target')
Hunting down where the issue lies has been a bit tricky, any assistance or advice would be greatly welcomed.