Last active
July 17, 2025 15:18
-
-
Save ggorlen/f7928b008fc111302414ab106f1cd729 to your computer and use it in GitHub Desktop.
Read XLSX in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const XLSX = require("xlsx"); // 0.18.5 | |
const workbook = XLSX.readFile("foo.xlsx", { cellDates: true }); | |
const sheetName = workbook.SheetNames[0]; | |
const worksheet = workbook.Sheets[sheetName]; | |
const data = XLSX.utils.sheet_to_json(worksheet, { defval: "" }); | |
console.log(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { getXlsxStream } = require("xlstream"); // ^2.5.5 | |
(async () => { | |
try { | |
const stream = await getXlsxStream({ | |
filePath: "/Users/greg/Downloads/test_test.xlsx", | |
sheet: 0, // or: "Some sheet name" | |
withHeader: true, | |
ignoreEmpty: true, | |
}); | |
for await (const row of stream) { | |
console.log(row.formatted.obj); | |
} | |
console.log("Done."); | |
} catch (err) { | |
console.error("Error:", err); | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { getXlsxStream } = require("xlstream"); // ^2.5.5 | |
(async () => { | |
const stream = await getXlsxStream({ | |
filePath: "/Users/greg/Downloads/test_test.xlsx", | |
sheet: 0, // or: "Some sheet name" | |
withHeader: true, | |
ignoreEmpty: true, | |
}); | |
stream.on("data", (row) => { | |
console.log(row.formatted.obj); | |
}); | |
stream.on("end", () => { | |
console.log("Done."); | |
}); | |
stream.on("error", (err) => { | |
console.error("Error:", err); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment