Convert Excel to JSON using Nodejs: 2 Minutes

preview_player
Показать описание
Install: npm install xlsx
var XLSX = require("xlsx");
var sheet_name_list = workbook.SheetNames;

var worksheet = workbook.Sheets[y];
//getting the complete sheet

var headers = {};
var data = [];
for (z in worksheet) {
if (z[0] === "!") continue;
//parse out the column, row, and value

var value = worksheet[z].v;

//store header names
if (row == 1) {
headers[col] = value;
// storing the header names
continue;
}

if (!data[row]) data[row] = {};
data[row][headers[col]] = value;
}
//drop those first two rows which are empty
});
Рекомендации по теме
Комментарии
Автор

You just saved me 12.7221 hours of searching in excel. Thank you bro
Keep up the good work. Let me check your channel while i procrastinate on this project.

derricknuby
Автор

Hi really nice video, but i have few doubts.. what if the cells are empty, a cell is enlarged and divided into multiple sections with data?
how can we convert to json with corresponding headers

nandhakumargp
Автор

how to convert date from "44928" to normal date?

tccnmqj
Автор

This is amazing work man but why not place the code on a git hub repo

desirechiduku