Skip to content

Instantly share code, notes, and snippets.

@brianpooe
Forked from davidcsejtei/ImportFromExcel.js
Created December 4, 2020 21:45
Show Gist options
  • Save brianpooe/abc303467f2f98bb2de47ab09dd4ff87 to your computer and use it in GitHub Desktop.
Save brianpooe/abc303467f2f98bb2de47ab09dd4ff87 to your computer and use it in GitHub Desktop.
const xlsx = require('xlsx');
const filePath = process.argv.slice(2)[0];
const workbook = xlsx.readFile(filePath);
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
let posts = [];
let post = {};
for (let cell in worksheet) {
const cellAsString = cell.toString();
if (cellAsString[1] !== 'r' && cellAsString[1] !== 'm' && cellAsString[1] > 1) {
if (cellAsString[0] === 'A') {
post.title = worksheet[cell].v;
}
if (cellAsString[0] === 'B') {
post.author = worksheet[cell].v;
}
if (cellAsString[0] === 'C') {
post.released = worksheet[cell].v;
posts.push(post);
post = {};
}
}
}
console.log(posts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment