-
-
Save ryanwild/b9099f1503ae034d634e8272ccedc8a3 to your computer and use it in GitHub Desktop.
Get all rows from all sheets in a excel doc as json array
This file contains 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
// Get all rows from all sheets in a excel doc as json array | |
// Assumes sheets have header rows | |
const XLSX = require('xlsx'); | |
const jsonfile = require('jsonfile'); | |
const R = require('ramda'); | |
const getWorkbook = () => XLSX.readFile('./data/test.xlsx'); | |
const pickSheetsByName = (workbook) => R.pick(workbook.SheetNames, workbook.Sheets); | |
const getAllRowsFromAllSheets = R.pipe( | |
R.pick(["Sheets", "SheetNames"]), | |
pickSheetsByName, | |
R.values, | |
R.map(XLSX.utils.sheet_to_json), | |
R.reduce(R.concat, []) | |
) | |
jsonfile.writeFileSync('./data/workbook.json', getAllRowsFromAllSheets(getWorkbook())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment