Skip to content

Instantly share code, notes, and snippets.

@RaviPabari
Created October 13, 2021 13:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaviPabari/12fae6e9a38286db0fcfa99eac109998 to your computer and use it in GitHub Desktop.
Save RaviPabari/12fae6e9a38286db0fcfa99eac109998 to your computer and use it in GitHub Desktop.
Convert excel sheet to JSON data with Node Js using xlsx lib
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