添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Repository files navigation

table-xlsx

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

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

📦 安装

使用npm或yarn

npm install --save table-xlsx @pengchen/xlsx
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) 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

render 生成复杂数据的渲染函数,参数分别为当前行的值,当前行数据,行索引,@return 里面可以设置表格行/列合并 function(text, record, index) {} xlsxRender 设置xlsx列导出值,参数分别为当前行的值,当前行数据,行索引,返回String类型 function(text, record, index) { return String } onTxBodyCell 设置表格主体单元格,@return里可设置单元格样式;如果是多级表头,需要设置在末级列 function(record, index) { return { style } }

cellStyle、headerCellStyle、bodyCellStyle、txHeaderCellStyle、onTxBodyCell().style

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' alignmentVertical 垂直对齐(top、center、bottom) string 'center' alignmentWrapText 自动换行(true、false) boolean false alignmentReadingOrder number alignmentTextRotation 文本旋转(0 to 180 or 255) number

parseFile