onFileSelected(files: FileList) {
console.log(files)
console.log(files[0])
this.csvIsParsing = true;
let file = files[0];
let csvType = "application/vnd.ms-excel";
let xlsxType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
if (file.type !== csvType && file.type !== xlsxType) {
this.wrongFileTypeError = true;
this.csvIsParsing = false;
return;
} else if (files.length > 1) {
this.tooManyFilesError = true;
this.csvIsParsing = false;
return;
}
this.fileName = file.name;
this.checkFileSize(file.size);
this.wrongFileTypeError = false;
this.tooManyFilesError = false;
if (files.length > 0 && file.type === csvType) {
this.csvParser.parse(file, {
header: this.hasCsvHeader,
skipEmptyLines: true,
dynamicTyping: true,
encoding: "ISO-8859-1",
complete: (result) => {
console.log('Parsed: ', result.data);
this.csvData = result.data;
this.dataSource = new MatTableDataSource(result.data);
this.dataSource.sort = this.sort;
setTimeout(() => this.dataSource.paginator = this.paginator);
for (let col in this.csvData[0]) {
this.displayedColumns.push(col);
}
console.log(this.dataSource);
this.csvIsParsing = false;
}
});
}
}