'Get headers row REACT XLSX

I'm currently working with an excel document, but I need to get only the table headers name. So far my code looks like this

if(file){
    let fileReader = new FileReader();
    fileReader.readAsBinaryString(file);
    fileReader.onload = (event) =>{
      let data = event.target?.result;
      let workbook = XLSX.read(data,{type:"binary"});
      console.log('WORKBOOK',workbook)
      workbook.SheetNames.forEach(sheet => {
        let rowObject = XLSX.utils.sheet_to_json(workbook.Sheets[sheet])
        console.log('RowObject',rowObject)
        setFile(rowObject)
      })
    }
  }

Workbook output: enter image description here

Inside the Sheets object, I can see the cells, including the header name, how can I get only the header row? enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source