1.2.0 • Published 9 months ago

js-data-to-csv v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

js-data-to-csv

⚠️ 只能运行在浏览器环境下,支持typescript,1w条数据3s内下载完成(不同设备情况不一)

安装

$ npm install js-data-to-csv

使用

1.导入包

import exportExcel from 'js-data-to-csv';

2.使用exportExcel函数 | prop| type | required | description| | --- | --- | ---| --- | |sourceData | 对象 | true | 要导出为.csv文件的对象| |name| string| trye|.csv文件名|

const sourceData = {
  // 表格头
  head: [
    { title: "时间", fieldName: "time" },
    { title: "成交价格", fieldName: "tradePrice" },
    { title: "手续费", fieldName: "fee" },
    { title: "成交金额", fieldName: "tradeAmount" }
  ],
  // 数据内容
  body: [
    {
      time: "2019-10-17 14:54:52",
      tradePrice: "30.0022.001.32 TWD",
      fee: "0 TWD",
      tradeAmount: "660.00"
    }
    // ... more
  ]
};

example

// 1.导入
import exportExcel from 'js-data-to-csv';

// 2.整理数据格式
const sourceData = {
  head: [
    { title: "时间", fieldName: "time" },
    { title: "成交价格", fieldName: "tradePrice" },
    { title: "手续费", fieldName: "fee" },
    { title: "成交金额", fieldName: "tradeAmount" }
  ],
  body: [
    {
      time: "2019-10-17 14:54:52",
      tradePrice: "30.0022.001.32 TWD",
      fee: "0 TWD",
      tradeAmount: "660.00"
    },
    {
      time: "2019-10-17 14:54:36",
      tradePrice: "30.0089.005.34 TWD",
      fee: "",
      tradeAmount: "2,670.00"
    },
    {
      time: "2019-10-17 14:54:07",
      tradePrice: "21.00500.0021 TWD",
      fee: "0 TWD",
      tradeAmount: "10,500.00"
    }
  ]
};

// 3.调用函数
exportExcel(sourceData,'cardTable')
1.2.0

9 months ago

1.1.0

9 months ago

1.0.0

9 months ago