Skip to content

Instantly share code, notes, and snippets.

@davidcsejtei
Last active May 28, 2022 15:17
Show Gist options
  • Save davidcsejtei/21a1d689ba86a6f5093974631f5a3986 to your computer and use it in GitHub Desktop.
Save davidcsejtei/21a1d689ba86a6f5093974631f5a3986 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);
const xlsx = require('xlsx');
const filePath = process.argv.slice(2)[0];
const workbook = xlsx.readFile(filePath);
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
const data = xlsx.utils.sheet_to_json(worksheet, {
header: "A",
range: 9
});
data.map(aa => {
console.log(aa);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment