Skip to content

Released v1.1.4

Compare
Choose a tag to compare
@LuisEnMarroquin LuisEnMarroquin released this 05 Sep 18:01

json-as-xlsx

This is a tool that helps to build an excel from a json and it depends only on xlsx

You can see a live example of how it works on this site: luisenmarroquin.github.io/json-as-xlsx

Usage

Just import and use it

var xlsx = require('json-as-xlsx')

var columns = [
  { label: 'Email', value: 'email' }, // Top level data
  { label: 'Age', value: row => (row.age + ' years') }, // Run functions
  { label: 'Password', value: row => (row.hidden ? row.hidden.password : '') }, // Deep props
]

var content = [
  { email: 'Ana', age: 16, hidden: { password: '11111111' } },
  { email: 'Luis', age: 19, hidden: { password: '12345678' } }
]

var settings = {
  sheetName: 'First sheet', // The name of the sheet
  fileName: 'Users', // The name of the spreadsheet
  extraLength: 3 // A bigger number means that columns should be wider
}

var download = true // If true will download the xlsx file, otherwise will return a buffer

xlsx(columns, content, settings, download) // Will download the excel file

Examples

This are my files used for development, remember to change:

require('./index.js') and require('../index.js') to require('json-as-xlsx')