Skip to content

Instantly share code, notes, and snippets.

@SneakyPeet
Created May 10, 2017 09:20
Show Gist options
  • Save SneakyPeet/ba29305262fd776112a87bce98126416 to your computer and use it in GitHub Desktop.
Save SneakyPeet/ba29305262fd776112a87bce98126416 to your computer and use it in GitHub Desktop.
Get all rows from all sheets in a excel doc as json array
// 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