adonis-spreadsheet
v1.0.1
Published
Spread sheet provider for adonis framework and has support for csv, xls, xlsx, ods
Downloads
792
Maintainers
Readme
Adonis Spread Sheet
This is repo is a AdonisJs provider for simplicity work with sheets docs. It's base on powerful SheetJS
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