0.2.2 • Published 7 years ago

node-json-xlsx v0.2.2

Weekly downloads
308
License
BSD-2-Clause
Repository
github
Last release
7 years ago

node-json-xlsx

utility to convert json to a excel file, based on Node-Excel-Export

Installation

npm install node-json-xlsx

Usage

Use to save as file:

var json2xlsx = require('node-json-xlsx');
var json = {
    foo: 'bar',
    qux: 'moo',
    poo: 123,
    stux: new Date()
}

var xlsx = json2xlsx(json);

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

Options

As a second parameter to json2xlsx or a third parameter to res.xlsx, a map of options can be passed:

var xlsx = json2xlsx(json, options);
res.xlsx('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 json2xlsx = require('node-json-xlsx');
var json = {
    foo: 'bar',
    qux: 'moo',
    poo: 123,
    stux: new Date()
}

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

//export only the field 'poo' as string
var xlsx = json2xlsx(json,{
    fields: {poo:'string'},
    fieldNames: ['Poo']

});

fs.writeFileSync('data.xlsx', xlsx, 'binary');
0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.3

7 years ago