Skip to content Skip to sidebar Skip to footer

How To Get Excel Sheet Names In JavaScript

I am trying to get the list of the sheets from an excel file in order to display it in a combobox. The idea is that the user can select the file that he want to import from an exce

Solution 1:

Detail explaination can be found Here

                 sheet.forEach(function (y) { /*Iterate through all sheets*/  
                     /*Convert the cell value to Json*/  
                                     var  exceljson = XLSX.utils.sheet_to_json(workbook.Sheets[y]);  
                       
                     
                 });  

Solution 2:

In NodeJS you can use the Node XLSX (NodeJS excel file parser & builder). There is a parse method that reads the Excel file and gives you an array of all it's sheets. Then you could loop the array and get the name of each sheet and all the data. To Install the package use:

npm install node-xlsx --save

This code will print all the sheet names in an Excel file:

var xlsx = require('node-xlsx');
const worksheetsArray = xlsx.parse('example.xlsx'); // parses a file
worksheetsArray.forEach(sheet => {
    console.log(sheet.name);
})

Solution 3:

I like to use the following lib: npm install xlsx

const xlsx = require('xlsx')
const workbook = xlsx.readFile(file); //Here you should pass the file path
const sheetList = workbook.SheetNames; //Array of sheet names.
console.log(sheetList)

Post a Comment for "How To Get Excel Sheet Names In JavaScript"