Focusing on the first half of the first line of the question: how to convert Excel to json.
Assume: Excel spreadsheet is a square of data, where the first row is object keys and remaining rows are object values and the desired json is a list of objects.
Improvements on previous answer: remove unnecessary splits and joins (unnecessary and could cause invalid transforms if keys or values contained commas), allow dotted strings in keys to imply nested objects, coffeescript, write the file.
Dotted notation: Key row (0) containing firstName, lastName, address.street, address.city, address.state, address.zip would product, per row, a doc with first and last names and an embedded doc named address, with the address.
assign function by VisioN from How to set object property (of object property of..) given its string name in JavaScript?
First, load the excel module
npm install excel --save-dev
Not elegant, just get'r'done code
fs = require 'fs'
excel = require 'excel'
FILES = [
{src: 'input.xlsx', dst: 'output.json'}
]
# Assign values to dotted property names - set values on sub-objects
assign = (obj, key, value) ->
# Because we recurse, a key may be a dotted string or a previously split
# dotted string.
key = key.split '.' unless typeof key is 'object'
if key.length > 1
e = key.shift()
obj[e] = if Object.prototype.toString.call(obj[e]) is "[object Object]" then obj[e] else {}
assign obj[e], key, value
else
obj[key[0]] = value
# The excel module reads sheet 0 from specified xlsx file
process = (src, dst) ->
excel src, (err, data) ->
throw err if err
keys = data[0]
rows = data[1..]
result = []
for row in rows
item = {}
assign item, keys[index], value for value, index in row
result.push item
fs.writeFile dst, JSON.stringify(result, null, 2), (err) ->
if err
console.error("Error writing file #{dst}", err)
else
console.log "Updated #{dst}"
process file.src, file.dst for file in FILES