#!/usr/bin/env node // Converts .xls/.xlsx to JSON on stdout. // Usage: node xls2json.js const XLSX = require(__dirname + '/node_modules/xlsx'); const path = require('path'); const file = process.argv[2]; if (!file) { process.stderr.write('usage: xls2json.js \n'); process.exit(1); } try { const wb = XLSX.readFile(file); const ws = wb.Sheets[wb.SheetNames[0]]; const rows = XLSX.utils.sheet_to_json(ws, { header: 1, defval: '' }); process.stdout.write(JSON.stringify(rows)); } catch (e) { process.stderr.write('xls2json error: ' + e.message + '\n'); process.exit(2); }