1 | # :dizzy: JavaScript Object to csv, xls, pdf, doc and DOM to html 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 |
|
6 | A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript Object or DOM element only from the frontend!
|
7 |
|
8 | ## Demo
|
9 |
|
10 | Please navigate to the following demo to test this library: [Demo Page](http://gharibi.github.io/JsObjExporter/examples/example.html)
|
11 |
|
12 | ## Installation
|
13 |
|
14 | You can download the latest version of ObjectExporter from the [GitHub releases](https://github.com/gharibi/JsObjExporter/releases/latest).
|
15 |
|
16 |
|
17 | ## Configuration
|
18 |
|
19 | In order use this library, follow the below steps:
|
20 |
|
21 | 1. Download the latest release of the library from [GitHub releases](https://github.com/gharibi/JsObjExporter/releases/latest).
|
22 |
|
23 | 2. Add the reference to the library in your `HTML` file:
|
24 |
|
25 | ```
|
26 | <script src='<path>/objectexporter.min.js'></script>
|
27 | ```
|
28 |
|
29 | 2. Paste the following to your `JavaScript` code and provide the required values as mentioned below:
|
30 |
|
31 | ```
|
32 | objectExporter({
|
33 | exportable: <object>, // The dataset to be exported form an array of objects, it can also be the DOM name for exporting DOM to html
|
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 | fileName: <string>, // The name of the file which will be exported without the extension.
|
41 | headerStyle: <cssStyle>, // The style which needs to be applied to the column headers
|
42 | cellStyle: <cssStyle>, // The style which needs to be applied to each of the cells excluding the headers
|
43 | sheetName: <string>, // The sheet name containing the exported exportables
|
44 | documentTitle: <string>, // The document title which should be added to the printable
|
45 | documentTitleStyle: <cssStyle>, // The style which can be applied to the document header
|
46 | repeatHeader: <boolean>, // The table header repeat parameter
|
47 | columnSeparator: <char|string> // The expected column column separator in csv export
|
48 | })
|
49 | ```
|
50 |
|
51 | ### Aurguments description
|
52 | ObjectExporter currently supports the below arguments:
|
53 |
|
54 | | Argument | Data Type | Required? | Default Value | Acceptable Values | Description | Applicable to |
|
55 | | - | - | - | - | - | - | - |
|
56 | | 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 |
|
57 | | type | string | yes | no default | csv, xls or pdf | This specifies the file type for generating the export. | csv, xls, pdf and doc |
|
58 | | 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 |
|
59 | | fileName | string | no | export | any acceptable string for the file name | This specifies the name for the export. | csv, xls, pdf and doc |
|
60 | | headerStyle | string | no | font-size:16px; font-weight:bold; | CSS style | This specifies the style for the exported headers. | xls, pdf and doc |
|
61 | | cellStyle | string | no | font-size:14px; | CSS style | This specifies the style for the exported cells. | xls, pdf and doc |
|
62 | | sheetName | string | no | worksheet | any string | This specifies the sheet name for the excel file. | xls |
|
63 | | documentTitle | string | no | test document title | any string | This specifies the exportable file title. | pdf and doc |
|
64 | | documentTitleStyle | string | no | color:red; | any string | This specifies the style for the document title. | pdf and doc |
|
65 | | repeatHeader | boolean | no | true | any string | This specifies the exportable header, whether it should be repeated accross various pages. | pdf and doc |
|
66 | | columnSeparator | char/string | no | , | any string or character | This specifies the column separator in csv export | csv |
|
67 |
|
68 | (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.
|
69 |
|
70 | ## Contribution
|
71 |
|
72 | Any contribution is always appreciated! :thumbsup: :thumbsup: :thumbsup:
|
73 |
|
74 | In order to have this project installed in your development environment for the contribution purpose, follow the below steps:
|
75 |
|
76 | 1. Fork this repository.
|
77 |
|
78 | 2. Clone your forked repo. Then navigate to the downloaded folder and get the required packages for the library by:
|
79 | ```
|
80 | npm install
|
81 | ```
|
82 |
|
83 | 3. Build the library locally by:
|
84 | ```
|
85 | npm run build
|
86 | ```
|
87 |
|
88 | 4. Check `test.html` under the example folder to test the library:
|
89 | ```
|
90 | npm install httpserver -g
|
91 | httpserver
|
92 | ```
|
93 |
|
94 | Then navigate to:
|
95 | `http://localhost:8080/test.html`
|
96 |
|
97 | 5. Now make your changes in the library.
|
98 |
|
99 | 6. 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:
|
100 |
|
101 | 7. Once you are done, check your code style by:
|
102 | ```
|
103 | npm run test
|
104 | ```
|
105 |
|
106 | In case there are issues, please resolve them before pushing the code.
|
107 |
|
108 | 8. Well done! now push your code and make a pull request. :rocket:
|
109 |
|
110 | ## License
|
111 |
|
112 | ObjectExporter is available under the [MIT license](https://github.com/gharibi/JsObjExporter/blob/master/LICENSE).
|