Skip to content
json导出excel(纯js 支持中文) ES6 module
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example width Jul 16, 2018
lib 1.1.1 Aug 15, 2018
src 1.1.1 Aug 15, 2018
.babelrc
.eslintrc 1.0.5 May 2, 2018
.gitignore [*] packages, cleaned up babel preset and updated packages to newest … Jan 10, 2018
README.md Update README.md Aug 26, 2019
build.js 1.1.1 Aug 15, 2018
index.js [*] change the implement method which doesn't use class syntax. Jan 10, 2018
package.json v1.1.2 Aug 16, 2018
webpack.config.js 1.0.5 May 2, 2018
yarn.lock 1.0.5 May 2, 2018

README.md

js-export-excel

纯 js 导出 excel

tip

Bug please mention on issues

log

  • 2018.8.15 (v: 1.1.1)

    优化打包 添加 babel 编译

  • 2018.7.16 (v: 1.1.0)

    添加列宽设置

download

npm install js-export-excel

or

yarn add js-export-excel

documentation

const ExportJsonExcel = require('js-export-excel')

var option={};

option.fileName = 'excel'
option.datas=[
  {
    sheetData:[{one:'一行一列',two:'一行二列'},{one:'二行一列',two:'二行二列'}],
    sheetName:'sheet',
    sheetFilter:['two','one'],
    sheetHeader:['第一列','第二列'],
    columnWidths: [20, 20]
  },
  {
    sheetData:[{one:'一行一列',two:'一行二列'},{one:'二行一列',two:'二行二列'}]
  }
];

var toExcel = new ExportJsonExcel(option); //new
toExcel.saveExcel(); //保存

option

  • datas 数据

    /*多个sheet*/
    /*每个sheet为一个object */
    [{
    sheetData:[], // 数据
    sheetName:'', // sheet名字
    sheetFilter:[], //列过滤
    sheetHeader:[] // 第一行
    columnWidths: [] //列宽 需与列顺序对应
    }]
  • fileName 下载文件名(默认:download)

sheet option

  • sheetName sheet 名字(可有可无)(默认 sheet1)

  • sheetHeader 标题(excel 第一行数据)

    sheetHeader: ["第一列", "第二列"];
  • columnWidths 列宽 非必须

    // number 屏幕宽度为100 20即为 1/5屏幕大小
    columnWidths = [20, ""];
  • sheetData 数据源(必须)

    <!--两种形式-->
    <!--第一种 object-->
    [{one:'一行一列',two:'一行二列'},{one:'二行一列',two:'二行二列'}]
    <!--第二种 arrary-->
    [['一行一列','一行二列'],['二行一列','二行二列']]
  • sheetFilter 列过滤(只有在 data 为 object 下起作用)(可有可无)

    sheetFilter = ["two", "one"];

效果预览

Paste_Image.png

浏览器支持

ie 10+

You can’t perform that action at this time.