Skip to content

Releases: LuisEnMarroquin/json-as-xlsx

Released v2.2.3

09 Nov 00:04
Compare
Choose a tag to compare

json-as-xlsx

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

Now with version 2.0.0 and above supports multiple sheets and custom styling

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

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

let data = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: 'user.more.phone' }, // Deep props
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

let settings = {
  fileName: 'MySpreadsheet', // Name of the spreadsheet
  extraLength: 3, // A bigger number means that columns will be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

xlsx(data, settings) // Will download the excel file

TypeScript

Here is an example of a server setup using TS, thanks to @elyse0 for the contribution

import xlsx, { IJsonSheet, ISettings } from 'json-as-xlsx'
import express from 'express'

const app = express()
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

const data: IJsonSheet[] = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' },
      { label: 'Age', value: 'age' }
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' },
      { label: 'Age', value: 'age' }
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

const settings: ISettings = {
  writeOptions: {
    type: 'buffer',
    bookType: 'xlsx'
  }
}

app.get('/', (_, res) => {
  const buffer = xlsx(data, settings)
  res.writeHead(200, {
    'Content-Type': 'application/octet-stream',
    'Content-disposition': 'attachment; filename=MySheet.xlsx'
  })
  res.end(buffer)
})

const port = process.env.PORT ?? 3000

app.listen(port, () => {
  console.log(`Your app is listening on port ${port}`)
})

Examples

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

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

Released v2.2.2

07 Nov 07:05
Compare
Choose a tag to compare

json-as-xlsx

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

Now with version 2.0.0 and above supports multiple sheets and custom styling

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

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

let data = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: 'user.more.phone' }, // Deep props
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

let settings = {
  fileName: 'MySpreadsheet', // Name of the spreadsheet
  extraLength: 3, // A bigger number means that columns will be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

xlsx(data, settings) // Will download the excel file

TypeScript

Here is an example of a server setup using TS, thanks to @elyse0 for the contribution

import xlsx, { IJsonSheet, ISettings } from 'json-as-xlsx'
import express from 'express'

const app = express()
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

const data: IJsonSheet[] = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' },
      { label: 'Age', value: 'age' }
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' },
      { label: 'Age', value: 'age' }
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

const settings: ISettings = {
  writeOptions: {
    type: 'buffer',
    bookType: 'xlsx'
  }
}

app.get('/', (_, res) => {
  const buffer = xlsx(data, settings)
  res.writeHead(200, {
    'Content-Type': 'application/octet-stream',
    'Content-disposition': 'attachment; filename=MySheet.xlsx'
  })
  res.end(buffer)
})

const port = process.env.PORT ?? 3000

app.listen(port, () => {
  console.log(`Your app is listening on port ${port}`)
})

Examples

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

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

Released v2.2.1

07 Nov 05:21
Compare
Choose a tag to compare

json-as-xlsx

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

Now with version 2.0.0 and above supports multiple sheets and custom styling

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

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

let data = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: 'user.more.phone' }, // Deep props
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

let settings = {
  fileName: 'MySpreadsheet', // Name of the spreadsheet
  extraLength: 3, // A bigger number means that columns will be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

xlsx(data, settings) // Will download the excel file

TypeScript

const jsonSheets: IJsonSheet[] = [{
  sheet: "Friends",
  columns: [
    { label: "Name", value: "name" },
    { label: "Username", value: "username" }
  ],
  content: [
    { name: "Andreas", username: "andr34s" }
  ]
}]

xlsx(jsonSheets)

Examples

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

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

Released v2.2.0

07 Nov 02:04
Compare
Choose a tag to compare

json-as-xlsx

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

Now with version 2.0.0 and above supports multiple sheets and custom styling

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

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

let data = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: 'user.more.phone' }, // Deep props
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

let settings = {
  fileName: 'MySpreadsheet', // Name of the spreadsheet
  extraLength: 3, // A bigger number means that columns will be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

xlsx(data, settings) // Will download the excel file

TypeScript

const jsonSheets: IJsonSheet[] = [{
  sheet: "Friends",
  columns: [
    { label: "Name", value: "name" },
    { label: "Username", value: "username" }
  ],
  content: [
    { name: "Andreas", username: "andr34s" }
  ]
}]

xlsx(jsonSheets)

Examples

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

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

Released v2.1.0

18 Aug 03:22
Compare
Choose a tag to compare

json-as-xlsx

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

Now with version 2.0.0 and above supports multiple sheets and custom styling

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

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

let data = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

let settings = {
  fileName: 'MySpreadsheet', // Name of the spreadsheet
  extraLength: 3, // A bigger number means that columns will be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

xlsx(data, settings) // 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')

Released v2.0.1

23 Jul 04:02
Compare
Choose a tag to compare

json-as-xlsx

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

Now with version 2.0.0 and above supports multiple sheets and custom styling

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

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

let data = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

let settings = {
  fileName: 'MySpreadsheet', // Name of the spreadsheet
  extraLength: 3, // A bigger number means that columns will be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

xlsx(data, settings) // 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')

Released v2.0.0

07 Jun 22:59
Compare
Choose a tag to compare

json-as-xlsx

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

Now with version 2.0.0 and above supports multiple sheets and custom styling

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

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

let data = [
  {
    sheet: 'Adults',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Andrea', age: 20, more: { phone: '11111111' } },
      { user: 'Luis', age: 21, more: { phone: '12345678' } }
    ]
  }, {
    sheet: 'Children',
    columns: [
      { label: 'User', value: 'user' }, // Top level data
      { label: 'Age', value: row => (row.age + ' years') }, // Run functions
      { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
    ],
    content: [
      { user: 'Manuel', age: 16, more: { phone: '99999999' } },
      { user: 'Ana', age: 17, more: { phone: '87654321' } }
    ]
  }
]

let settings = {
  fileName: 'MySpreadsheet', // Name of the spreadsheet
  extraLength: 3, // A bigger number means that columns will be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

xlsx(data, settings) // 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')

Released v1.2.1

21 Mar 02:01
Compare
Choose a tag to compare

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: 'User', value: 'user' }, // Top level data
  { label: 'Age', value: row => (row.age + ' years') }, // Run functions
  { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
]

var content = [
  { user: 'Ana', age: 16, more: { phone: '11111111' } },
  { user: 'Luis', age: 19, more: { phone: '12345678' } }
]

var settings = {
  sheetName: 'FirstSheet', // The name of the sheet
  fileName: 'MySpreadsheet', // The name of the spreadsheet
  extraLength: 3, // A bigger number means that columns should be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

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')

Released v1.2.0

21 Feb 17:43
Compare
Choose a tag to compare

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: 'User', value: 'user' }, // Top level data
  { label: 'Age', value: row => (row.age + ' years') }, // Run functions
  { label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
]

var content = [
  { user: 'Ana', age: 16, more: { phone: '11111111' } },
  { user: 'Luis', age: 19, more: { phone: '12345678' } }
]

var settings = {
  sheetName: 'FirstSheet', // The name of the sheet
  fileName: 'MySpreadsheet', // The name of the spreadsheet
  extraLength: 3, // A bigger number means that columns should be wider
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

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')

Released v1.1.8

24 Oct 01:52
Compare
Choose a tag to compare

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: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
]

var content = [
  { email: 'Ana', age: 16, more: { phone: '11111111' } },
  { email: 'Luis', age: 19, more: { phone: '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
  writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
}

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')