# json2xls

> canonically transform json to an excel document

Latest version **0.1.2** (published 2016-07-01) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install json2xls
pnpm add json2xls
yarn add json2xls
bun add json2xls
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2016-07-01 |
| First published | 2013-11-23 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | separate (@types/json2xls) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 278 |
| Author | Rikkert Koppes |
| Maintainers | rikkertkoppes |

## Links

- npm: https://www.npmjs.com/package/json2xls
- Repository: https://github.com/rikkertkoppes/json2xls
- Homepage: https://github.com/rikkertkoppes/json2xls#readme
- Issues: https://github.com/rikkertkoppes/json2xls/issues
- npm.io page: https://npm.io/package/json2xls

## Dependencies (1)

- [excel-export](https://npm.io/package/excel-export.md) ~0.3.11

## Recent versions

- 0.1.2 (latest) — 2016-07-01
- 0.1.1 — 2015-12-29
- 0.1.0 — 2015-12-04
- 0.0.5 — 2014-03-17
- 0.0.4 — 2014-03-17
- 0.0.3 — 2014-03-17
- 0.0.2 — 2014-03-13
- 0.0.1 — 2013-11-23

## README

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)

Installation
------------

    npm install json2xls

Usage
------

Use to save as file:

    var json2xls = require('json2xls');
    var json = {
        foo: 'bar',
        qux: 'moo',
        poo: 123,
        stux: new Date()
    }

    var xls = json2xls(json);

    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 = [{
        foo: 'bar',
        qux: 'moo',
        poo: 123,
        stux: new Date()
    },
    {
        foo: 'bar',
        qux: 'moo',
        poo: 345,
        stux: new Date()
    }];

    app.use(json2xls.middleware);

    app.get('/',function(req, res) {
        res.xls('data.xlsx', jsonArr);
    });

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);

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'

Example:

    var json2xls = require('json2xls');
    var 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' as string
    var xls = json2xls(json,{
        fields: {poo:'string'}
    });

    fs.writeFileSync('data.xlsx', xls, 'binary');

---
_Source: https://npm.io/package/json2xls · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
