• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

rikkertkoppes/json2xls: canonically transform json to an excel document

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

rikkertkoppes/json2xls

开源软件地址:

https://github.com/rikkertkoppes/json2xls

开源编程语言:

JavaScript 100.0%

开源软件介绍:

json2xls

Build Status

utility to convert json to a excel file, based on 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');



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap