@oniryk/dreamer-xls
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

@oniryk/dreamer-xls

npm version npm total downloads npm monthly downloads npm license build status

@oniryk/dreamer-xls is a wrapper of node-xlsx that provides a more convenient way to deliver AdonisJS v6 responses in xlsx format. This package is part of @oniryk/dreamer. It is not intended to be a general purpose package, but you can use it if you want.

Installation

npm install @oniryk/dreamer-xls

Usage

If you are using @oniryk/dreamer, you can use it like this:

import Post from '#models/post'
import { index } from '@oniryk/dreamer/extensions/crud'
import xls from '@oniryk/dreamer-xls'

export default class PostsController {
  public index = index(Post, {
    formats: [ xls() ],
  })
  // ..
}

You also can use it directly:

import { HttpContext } from '@adonisjs/core/http'
import xls from '@oniryk/dreamer-xls'

export default class PostsController {
  public async index(context: HttpContext) {
    const data = await Post.all()
    await xls()(context, data)
  }
}

Settings

You can pass an object to the xls function to customize the output:

xls({
  // Define the filename when downloading
  filename: 'posts.xlsx', // default is 'export.xlsx'
  // Define the sheet name
  sheetName: 'Posts',
  // Define the columns to export
  columns: ['title', 'content', 'author', 'created_at'],
  // Translate the column names
  i18n: {
    title: 'Title',
    content: 'Content',
  },
  // You can also pass the same options as node-xlsx
  // See https://www.npmjs.com/package/node-xlsx#usage
  sheetOptions: {
    '!cols': [
      { wch: 20 },
      { wch: 40 },
      { wch: 20 },
      { wch: 20 },
    ],
  },
})

Package Sidebar

Install

npm i @oniryk/dreamer-xls

Weekly Downloads

0

Version

0.0.5

License

MIT

Unpacked Size

7.09 kB

Total Files

5

Last publish

Collaborators

  • brunoziie