2.0.5 • Published 4 years ago

export-to-excel.js v2.0.5

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
4 years ago

Excel Export Service Package

An easy to use package to export your data into nice xls file. Be aware that this package send axios requests to an external server so you must be connected to the net, and it might take few seconds.

Install

npm install export-to-excel.js

Usage

First of all you need to wake up the external server, like this:

import ExcelService from 'export-to-excel.js';
ExcelService.wakeUp();

Put this code immediately after your application is up (it takes faw seconds to wake up the external server).

Simple export to excel

import ExcelService from 'export-to-excel.js';
const data = [{ "id": 5, "name": "John", "grade": 90, "age": 15 }, { "id": 7, "name": "Nick", "grade": 70, "age": 17 }];
ExcelService.export(data);

The excel file that will be downloaded looks like - alt text

Excel with headings If you want to control the excel headings you can do it easily by sending list of headings to the function:

import ExcelService from 'export-to-excel.js';
const data = [{ "id": 5, "name": "John", "grade": 90, "age": 15 }, { "id": 7, "name": "Nick", "grade": 70, "age": 17 }];
const headings = ["Student ID", "Student Name", "Test Grade", "Student Age"];
ExcelService.export(data, { headings });

The excel file that will be downloaded looks like - alt text

Name the file Currently the excel file name is 'excel'. You can override it:

const data = [{ "id": 5, "name": "John", "grade": 90, "age": 15 }, { "id": 7, "name": "Nick", "grade": 70, "age": 17 }];
const headings = ["Student ID", "Student Name", "Test Grade", "Student Age"];
const fileName = 'StudentsGrades';
ExcelService.export(data, { headings, fileName });

Async/Await

The method 'export' is promise based, so you can use it with async/await syntax:

const onExport = async () => {
    await ExcelService.export(this.data, { fileName: this.excelName });
    alert('Your excel file has been exported!'); // or some nicer ui indication...
}

Options

optiondescriptiondefault value
fileNamethe name of the excel file to be exportedexcel
headingsthe headings for the excel file, if not presented the headings will be the object keys-

License

MIT

2.0.5

4 years ago

1.2.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.4

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago