npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json2filejs

v1.0.3

Published

export json data to csv and xlsx file

Downloads

2

Readme

介绍

使用JS实现将Json数据为导出csv和xlsx文件。

使用场景

将渲染为表格的报表数据直接通过JS导出,省去再解析表格DOM。

依赖

本插件依赖FileSaver.jsjs-xlsx两个库,使用请先引入这两个库

<script src='./FileSaver.min.js'></script>
<script src='./xlsx.core.min.js'></script>

安装

  1. 通过npm安装使用
npm install json2filejs --save
import Json2fileJs from 'json2filejs'

<script src="./json2filejs/dist/index.min.js"></script>

用法

    const jsonFile = new Json2fileJs(headers, data, filename)
    jsonFile.exprotCSV() // 导出为csv文件
    jsonFile.exportXLSX() // 导出为xlsx文件

Json2fileJs接受三个参数,分别是表头headers数据data和文件名filename,后者为字符串类型,前两个参数均为对象数组, 如下:

const headers = [{  // 数据的键和表头名字
        key: 'name', // key对应data元素对象的key
        text: '名称' // name 为对应的表头名字
    }
];
const data = [{
    name: 'csv'
}]
`Json2fileJs` 实例化后拥有两个调用方法,分别是导出csv文件方法 `exprotCSV`  和导出xlsx文件方法 `exportXLSX`

例子

const headers = [{
        key: 'name',
        text: '名称'
    },
    {
        key: 'count',
        text: '使用量'
    }];
const data = [{
        name: 'csv',
        count: 10000
    },
    {
        name: 'xlsx',
        count: 100000000
    }];
const jsonFile =  new Json2fileJs(headers, data, 'file')

导出csv文件

 jsonFile.exprotCSV() // 导出为csv文件

导出为xlsx文件

jsonFile.exportXLSX() // 导出为xlsx文件