node-json-xlsx
v0.2.2
Published
canonically transform json to an excel document
Downloads
1,873
Readme
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');