Giter Site home page Giter Site logo

duobancc / table-xlsx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pengchen96/table-xlsx

2.0 1.0 0.0 7.24 MB

基于SheetJS封装,实现导出文件和解析文件生成表数据功能

Home Page: https://pengchen96.github.io/table-xlsx/docs/intro

License: MIT License

JavaScript 49.60% HTML 0.57% TypeScript 42.19% CSS 7.64%

table-xlsx's Introduction

table-xlsx

npm version Build Status codecov NPM downloads

基于SheetJS封装,帮助你快速将xlsx文件转换成表格数据或表格数据导出生成xlsx文件,导出支持简单样式设置、多sheet页、行/列合并等

文档&演示地址:https://pengchen96.github.io/table-xlsx/docs/intro

📦 安装

使用npm或yarn

npm install --save table-xlsx @pengchen/xlsx
# or
yarn add table-xlsx @pengchen/xlsx

使用CDN

<!-- 注意: 部署时,将 "development.umd.js" 替换为 "production.umd.js"-->
<script crossorigin src="https://unpkg.com/table-xlsx/dist/table-xlsx.development.umd.js"></script>

如果使用CDN的方式引入table-xlsx,建议设置crossorigin属性

CDN Availability (click to show)
CDN URL
unpkg https://unpkg.com/table-xlsx/
jsDelivr https://jsdelivr.com/package/npm/table-xlsx

🔨 使用

导出

import { exportFile } from "table-xlsx";

const columns = [
  { title: '姓名', dataIndex: 'name' },
  { title: '年龄', dataIndex: 'age' },
  { title: '住址', dataIndex: 'address' },
];
const dataSource = [
  { key: '1', name: '胡彦斌', age: 32, address: '西湖区湖底公园1号' },
  { key: '2', name: '胡彦祖', age: 42, address: '西湖区湖底公园1号' },
];

exportFile({ columns, dataSource });

解析

import { parseFile } from "table-xlsx";

parseFile({ file/*binary*/ }).then((result) => {
  // result = {
  //   wb, // wookbook对象
  //   tables: [{
  //     sheetName,
  //     dataSource,
  //     columns,
  //   },
  //   ...
  //   ]
  // }
});

📖 API

exportFile

参数 说明 类型 默认值
columns 表格列 array []
cellStyle 单元格样式 object {}
headerCellStyle 表头单元格样式 object {}
bodyCellStyle 主体单元格样式 object {}
dataSource 表格数据 array []
fileName 文件名 string 'table.xlsx'
showHeader 显示表头 bool true
raw 是否格式化值的类型 bool false
sheetNames sheet页 array ['sheet1']
useRender 使用render返回的值 boolean true

columns

参数 说明 类型 默认值
dataIndex 列数据在数据项中对应的路径,支持通过数组查询嵌套路径 string/string[] -
render 生成复杂数据的渲染函数,参数分别为当前行的值,当前行数据,行索引,@return 里面可以设置表格行/列合并 function(text, record, index) {} -
title 列头显示文字 string -
width 列宽度 string/number 100

cellStyle、headerCellStyle、bodyCellStyle

参数 说明 类型 默认值
fontName 字体 string 'Calibri'
fontColorRgb 字体颜色(ARGB) string '333333'
fontBold 加粗 boolean false
fillFgColorRgb 背景填充颜色(ARGB) string 'ffffff'
borderStyle 边框风格(thin、medium、thick、dotted、hair、dashed、mediumDashed、dashDot、mediumDashDot、dashDotDot、mediumDashDotDot、slantDashDot) string 'thin'
borderColorRgb 边框颜色(ARGB) string 'd1d3d8'
alignmentHorizontal 水平对齐(left、center、right) string 'center'
alignmentHorizontal 垂直对齐(top、center、bottom) string 'center'

parseFile

参数 说明 类型 默认值
file 文件 binary -

输出内容

    [
      {
        columns: [],
        dataSource: [],
        sheetName: ''
      },
      ...
    ]

📝 License

table-xlsx is available under the MIT License.

table-xlsx's People

Contributors

all-the-day avatar duobancc avatar pengchen96 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.