Created
October 13, 2021 13:23
-
-
Save RaviPabari/12fae6e9a38286db0fcfa99eac109998 to your computer and use it in GitHub Desktop.
Convert excel sheet to JSON data with Node Js using xlsx lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xlsx = require('xlsx') | |
function excelToJson() { | |
//read the whole sheet | |
const sheet = xlsx.readFile('/home/ravi/Desktop/message.xlsx') | |
//depending on the sheet you want to convert, in my case I wanted the to convert | |
//first sheet only | |
const first_sheet = sheet.SheetNames[0] | |
const sheet1 = sheet.Sheets[first_sheet] | |
//returns array of object mapped to key pair values dynamically | |
return xlsx.utils.sheet_to_json(sheet1) | |
} | |
data = excelToJson() | |
console.log(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment