1.0.1 • Published 7 years ago

adonis-spreadsheet v1.0.1

Weekly downloads
253
License
MIT
Repository
github
Last release
7 years ago

Adonis Spread Sheet

This is repo is a AdonisJs provider for simplicity work with sheets docs. It's base on powerful SheetJS

npm version Build Status Coverage Status

Install

npm i --save adonis-spreadsheet

Registering provider

The provider is registered inside start/app.js file under providers array.

const providers = [
  'adonis-spreadsheet/providers/SpreadSheetProvider'
]

That's all! Now you can use the mail provider as follows.

Getting started

const Route = use('Route')
const SpreadSheet = use('SpreadSheet')
const User = use('App/Models/User')

Route.get('/users/export/:format', async ({ request, response, params }) => {
  const ss = new SpreadSheet(request, params.format)
  
  const users = await User.all()
  const data = []
  
  data.push([
    'id',
    'First Name',
    'Last Name',
    'Email',
    'Phone'
  ])

  users.toJSON().forEach((user) => {
    data.push([
      user.id,
      user.first_name,
      user.last_name,
      user.phone
    ])
  })

  ss.addSheet('Users', data)
  ss.download('users-export')
})

Then you can fire url /rest/users/export/csv and received csv file sheet.

Supported formats

  • xls
  • xlsx
  • csv
  • ods