Click here to Skip to main content
15,037,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to read the Excel Data which contains the below format. The Actual Data will start from row no 7, row no 6 will have the headers. I want to start the data reading from row 7.

SL.No EmployeeName Worked Date Start Time End Time Worked Hours
1 AAAA 21-01-2021 10:00 16:00 6
2 BBBB 21-01-2021 11:00 16:00 5
........... .............. .................. .......... ............. ............
1000 XXXX 21-01-2021 08:00 17:00 9

What I have tried:

addfile(event)     
  {    
    let data, header;
    const target: DataTransfer = <DataTransfer>(event.target);
    this.isExcelFile = !!target.files[0].name.match(/(.xls|.xlsx)/);
    if (target.files.length > 1) {
      //this.inputFile.nativeElement.value = '';
    }
    if (this.isExcelFile) {
      this.spinnerEnabled = true;
      const reader: FileReader = new FileReader();
      reader.onload = (e: any) => {
        /* read workbook */
        const bstr: string = e.target.result;
        const wb: XLSX.WorkBook = XLSX.read(bstr, { type: 'binary' });

        /* grab first sheet */
        const wsname: string = wb.SheetNames[0];
        const ws: XLSX.WorkSheet = wb.Sheets[wsname];

        /* save data */
        data = XLSX.utils.sheet_to_json(ws);
      };

      reader.readAsBinaryString(target.files[0]);

      reader.onloadend = (e) => {
        this.spinnerEnabled = false;
        this.keys = Object.keys(data[0]);
        //console.log(this.keys);
        //console.log(data);
        for(var i = 5; i != data.length; ++i) 
        {
          console.log(data[i]);
        }
        //this.dataSheet.next(data)
      }
    } else {
      //this.inputFile.nativeElement.value = '';
    }   
}    
Posted
Updated 21-Jan-21 9:25am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900