UNPKG

5.5 kBMarkdownView Raw
1# :dizzy: JavaScript csv, xls, pdf and doc generator :dizzy:
2
3[![Gitter chat](https://badges.gitter.im/gharibi/JsObjectExporter.png)](https://gitter.im/JsObjectExporter/community)
4[![Build Status](https://api.travis-ci.org/gharibi/JsObjExporter.svg?branch=master)](https://travis-ci.org/gharibi/JsObjExporter) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE) [![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](http://standardjs.com/) [![npm](https://img.shields.io/npm/v/object-exporter.svg)](https://www.npmjs.com/package/object-exporter) [![Downloads/week](https://img.shields.io/npm/dw/object-exporter.svg)](https://www.npmjs.com/package/object-exporter) [![install size](https://packagephobia.now.sh/badge?p=object-exporter)](https://packagephobia.now.sh/result?p=object-exporter)
5
6A simple and quick javascript library for generating csv, xls, pdf and doc only on the frontend and without any need to communicate with the backend.
7
8## Example
9
10Please navigate to the following example to test this library: [Example Page](http://gharibi.github.io/JsObjExporter/examples/example.html)
11
12## Installation
13
14You can download the latest version of ObjectExporter from the [GitHub releases](https://github.com/gharibi/JsObjExporter/releases/latest).
15
16
17## Configuration
18
19In order use this library, follow the below steps:
20
211. Download the latest release of the library from [GitHub releases](https://github.com/gharibi/JsObjExporter/releases/latest).
22
232. Add the reference to the library in your `HTML` file:
24
25```
26<script src='<path>/objectexporter.min.js'></script>
27```
28
292. Paste the following to your `JavaScript` code and provide the required values mentioend below:
30
31```
32objectExporter({
33 exportable: data, // The dataset to be exported in form an array of objects
34 type: 'string', // The type of exportable e.g. csv, xls or pdf
35 headers: [{
36 name: 'string', // Name of the field without space to be used internally
37 alias: 'string', // The name of field which will be visualized in the export
38 flex: 'number' // An integer value which shows the relative width of this columns in comparison to the other columns
39 }],
40 // The name of the file which will be exported
41 fileName: 'string', // The name of the file which will be exported without the extension.
42 headerStyle: 'cssStyle', // The style which needs to be applied to the column headers
43 cellStyle: 'cssStyle', // The style which needs to be applied to each of the cells excluding the headers
44 sheetName: 'sheetNameForExportedFile' // The sheet name containing the exported exportables
45})
46```
47
48### Aurguments description
49ObjectExporter currently supports the below arguments:
50
51| Argument | Data Type | Required? | Default Value | Acceptable Values | Description | Applicable to |
52| - | - | - | - | - | - | - |
53| exportable | array of objects | yes | no default | `[{header1: value 1, header2: value 2},..., {headern: value n, headern+1: value n+1}]` | This is the array containing all of the objects which need to be exported. | csv, xls, pdf and doc |
54| type | string | yes | no default | csv, xls or pdf | This specifies the file type for generating the export. | csv, xls, pdf and doc |
55| headers | array or array of objects (1) | yes | no default | `[{name: 'fieldName1', alias: 'fieldAlias1', flex: flex1}, {name: 'fieldName2', alias: 'fieldAlias2', flex: flex2}, ..., {name: 'fieldNamen', alias: 'fieldAliasn', flex: flexn}]` | This specifies the headers for the exportable. | csv, xls, pdf and doc |
56| fileName | string | no | export | any acceptable string for the file name | This specifies the name for the export. | csv, xls, pdf and doc |
57| headerStyle | string | no | font-size:16px; font-weight:bold; | CSS style | This specifies the style for the exported headers. | xls, pdf and doc |
58| cellStyle | string | no | font-size:14px; | CSS style | This specifies the style for the exported cells. | xls, pdf and doc |
59| sheetName | string | no | worksheet | any string | This specifies the sheet name for the excel file. | xls |
60
61(1) In versions older than 3.3.0, `header` was defined as an array and not an array of objects. However from version 3.3.0, the library is backward-comptible, therefore array or array of objects, both are accepted.
62
63## Contribution
64
65Any contribution is always appreciated! :thumbsup: :thumbsup: :thumbsup:
66
67In order to have this project installed in your development environment for the contribution purpose, follow the below steps:
68
691. Fork this repository.
70
712. Clone your forked repo. Then navigate to the downloaded folder and get the required packages for the library by:
72```
73npm install
74```
75
763. Build the library locally by:
77```
78npm run build
79```
80
814. Check `test.html` under the example folder to test the library:
82```
83npm install httpserver -g
84httpserver
85```
86
87Then navigate to:
88`http://localhost:8080/test.html`
89
905. Now make your changes in the library.
91
926. Keep checking `test.html` after any changes and make sure the library is working fine. In case you add new features, feel free to add/modify tests:
93
947. Once you are done, check your code style by:
95```
96npm run test
97```
98
99In case there are issues, please resolve them before pushing the code.
100
1018. Well done! now push your code and make a pull request. :rocket:
102
103## License
104
105ObjectExporter is available under the [MIT license](https://github.com/gharibi/JsObjExporter/blob/master/LICENSE).