Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/updated readme #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 69 additions & 48 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
json2xls
========
# json2xls

[![Build Status](https://travis-ci.org/rikkertkoppes/json2xls.png?branch=master)](https://travis-ci.org/rikkertkoppes/json2xls)

utility to convert json to a excel file, based on [Node-Excel-Export](https://github.com/functionscope/Node-Excel-Export)
The utility for convert json to an excel file, based on [Node-Excel-Export](https://github.com/functionscope/Node-Excel-Export)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grammar here is not quite right I think. Other than that, the pr seems fine

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly do you want me to do? @rikkertkoppes


Installation
------------
---

npm install json2xls
## Installation

Usage
------
```sh
npm install json2xls
```

---

## Usage

Use to save as file:

var json2xls = require('json2xls');
var json = {
foo: 'bar',
qux: 'moo',
poo: 123,
stux: new Date()
}
```js
const json2xls = require('json2xls')

const json = {
foo: 'bar',
qux: 'moo',
poo: 123,
stux: new Date()
}

var xls = json2xls(json);
const xls = json2xls(json)

fs.writeFileSync('data.xlsx', xls, 'binary');
fs.writeFileSync('data.xlsx', xls, 'binary')
```

Or use as express middleware. It adds a convenience `xls` method to the response object to immediately output an excel as download.

var jsonArr = [{
```js
const json2xls = require('json2xls')

const jsonArr = [
{
foo: 'bar',
qux: 'moo',
poo: 123,
Expand All @@ -40,47 +50,58 @@ Or use as express middleware. It adds a convenience `xls` method to the response
qux: 'moo',
poo: 345,
stux: new Date()
}];
}
]

app.use(json2xls.middleware)

app.use(json2xls.middleware);
app.get('/', (req, res) => {
res.xls('data.xlsx', jsonArr)
})
```

app.get('/',function(req, res) {
res.xls('data.xlsx', jsonArr);
});
---

Options
-------
## Options

As a second parameter to `json2xls` or a third parameter to `res.xls`, a map of options can be passed:

var xls = json2xls(json, options);
res.xls('data.xlsx', jsonArr, options);
```js
const xls = json2xls(json, options)

res.xls('data.xlsx', jsonArr, options);
```

The following options are supported:

- style: a styles xml file, see <https://github.com/functionscope/Node-Excel-Export>
- fields: either an array or map containing field configuration:
- array: a list of names of fields to be exported, in that order
- object: a map of names of fields to be exported and the types of those fields. Supported types are 'number','string','bool'
- style: a styles xml file, see <https://github.com/functionscope/Node-Excel-Export>
- fields: either an array or map containing field configuration:
- array: a list of names of fields to be exported, in that order
- object: a map of names of fields to be exported and the types of those fields. Supported types are 'number','string','bool'

Example:
---

var json2xls = require('json2xls');
var json = {
foo: 'bar',
qux: 'moo',
poo: 123,
stux: new Date()
}
### Example:

```js
const json2xls = require('json2xls')

const json = {
foo: 'bar',
qux: 'moo',
poo: 123,
stux: new Date()
}

//export only the field 'poo'
var xls = json2xls(json,{
fields: ['poo']
});
// export only the field 'poo'
const xls = json2xls(json, {
fields: ['poo']
})

//export only the field 'poo' as string
var xls = json2xls(json,{
fields: {poo:'string'}
});
// export only the field 'poo' as string
const xls = json2xls(json, {
fields: { poo: 'string' }
})

fs.writeFileSync('data.xlsx', xls, 'binary');
fs.writeFileSync('data.xlsx', xls, 'binary')
```