I am using the below code where I am using , I am looking for a way where I can fix the filename with the proper path.
import { Component, OnInit } from '@angular/core';
import * as XLSX from 'xlsx';
@Component({
selector: 'app-excelsheet',
templateUrl: './excelsheet.component.html',
styleUrls: ['./excelsheet.component.css']
})
export class ExcelsheetComponent implements OnInit {
data: [][];
constructor() {}
ngOnInit(): void {
}
onFileChange(evt: any) {
const target: DataTransfer = < DataTransfer > (evt.target);
//const target : File ='Demo.XLSX';
if (target.files.length !== 1) throw new Error('Cammot use multiple files');
const reader: FileReader = new FileReader();
reader.onload = (e: any) => {
const bstr: string = e.target.result;
const wb: XLSX.WorkBook = XLSX.read(bstr, {
type: 'binary'
})
const wsname: string = wb.SheetNames[0];
const ws: XLSX.WorkSheet = wb.Sheets[wsname];
console.log(ws);
this.data = (XLSX.utils.sheet_to_json(ws, {
header: 1
}));
console.log(this.data);
}
reader.readAsBinaryString(target.files[0]);
}
}
I am using a drag a drop feature whereas I want to open a fix excel file, any idea how may I do this?
question from:https://stackoverflow.com/questions/65648578/how-to-open-a-fix-excel-file-in-angular-8