Skip to content

Instantly share code, notes, and snippets.

@nsourov
Created September 26, 2018 10:15
Show Gist options
  • Save nsourov/09310f12edc2b5258f8429e0632a426b to your computer and use it in GitHub Desktop.
Save nsourov/09310f12edc2b5258f8429e0632a426b to your computer and use it in GitHub Desktop.
var xlstojson = require("xls-to-json-lc");
var xlsxtojson = require("xlsx-to-json-lc");
function excelToJson(file) {
const ext = file.split(".").slice(-1)[0];
if (ext === "xlsx") {
xlsxtojson(
{
input: file,
output: `${__dirname}/output.json`
},
function(err, result) {
if (err) {
console.error(err);
} else {
console.log(result);
}
}
);
}
if (ext === "xls") {
xlstojson(
{
input: file,
output: `${__dirname}/output.json`
},
function(err, result) {
if (err) {
console.error(err);
} else {
console.log(result);
}
}
);
}
}
excelToJson(`${__dirname}/sample.xls`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment