Я пытаюсь импортировать файл Excel в проект с использованием библиотеки xlsx. У меня есть следующая функция ниже
public async ParseExcelFile(excelFile)
{
//Set up empty Excel Array
let excelContents : Array<any> = [];
let error : any = null;
return new Promise<Object>((resolve, reject) =>
{
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});
/* sheetstubs true supposedly shows empty cells but isn't */
const workSheetName: string = workBook.SheetNames[0];
const workSheet: XLSX.WorkSheet = workBook.Sheets[workSheetName];
this.data = <aoa>(XLSX.utils.sheet_to_json(workSheet,
{header: 1, blankrows: true }));
};
fileReader.readAsBinaryString(inputFile.files[0]);
{
// parse the excel data into the item format
let item : {level:number,ipn:string,quantity:number,refdes:string,revision:string,description:string,mfg:string,mpn:string,uom:string,isAlternate:boolean};
// push the item into the excel list
excelContents.push(item);
}
// if all ok? return the excel file contents
if(error)reject(error);
else resolve(excelContents);
});
, однако, когда я загружаю файл Excel, я сталкиваюсь со следующей ошибкой:
[Error] ERROR – Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'excelFile.target')
ZoneAwarePromise
step
ZoneAwarePromise
callWithDebugContext
dispatchEvent
onInvokeTask
invokeTask
globalZoneAwareCallback
Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'excelFile.target')
ZoneAwarePromise
step
ZoneAwarePromise
callWithDebugContext
dispatchEvent
onInvokeTask
invokeTask
globalZoneAwareCallbackresolvePromiseresolvePromise(anonymous function)step(anonymous function)ZoneAwarePromise(anonymous function)(anonymous function)callWithDebugContextdispatchEvent(anonymous function)onInvokeTask(anonymous function)(anonymous function)invokeTaskglobalZoneAwareCallback
defaultErrorLogger (core.umd.js:2639)
(anonymous function) (core.umd.js:2655)
next (core.umd.js:18520:144)
(anonymous function) (core.umd.js:16378)
(anonymous function) (Subscriber.js:205)
(anonymous function) (Subscriber.js:143)
(anonymous function) (Subscriber.js:89)
(anonymous function) (Subscriber.js:66)
(anonymous function) (Subject.js:60)
(anonymous function) (core.umd.js:16369:85)
(anonymous function) (zone.js:138)
onHandleError (core.umd.js:18173)
(anonymous function) (zone.js:152)
_loop_1 (zone.js:697)
(anonymous function) (zone.js:706)
drainMicroTaskQueue (zone.js:596)
(anonymous function) (zone.js:490)
invokeTask (zone.js:1650)
globalZoneAwareCallback (zone.js:1676)
однако, я не понимаю, что это за ошибка пытается сказать мне, и что может быть возможным решением этой проблемы.