Simon He @ simonhe.me

Exports Function

Jun 15 · 2day

Author: Simon

英文 English Version

此文是介绍封装的工具函数的文档exportsFunction

特点: 扩展性高,调用灵活便捷

更多

使用说明

npm i exports-function # 安装

import { 
  jsonExportZip,
  ...
 } from 'exports-function' # 按需引入

目录结构

01tableExportExcel
HTMLTableElement 转换为 Excel 导出
02jsonExportExcel
json导出成excel
03exportPdf
导出pdf

jsonExportZip

  • jJson is exported as a zip file
  • params:
    • header: string[]
    • data: any[][]
    • fileName: string
jsonExportZip({
  header: ['colums1', 'colums2', 'colums3'],
  data: [
    ['data1', 'data2', 'data3'],
    ['data4', 'data5', 'data6'],
    ['data7', 'data8', 'data9'],
  ],
  fileName: 'test',
})

tableExportExcel

  • HTMLTableElement Convert to Excel export
  • params:
    • table: HTMLTableElement | string
    • filename: string = 'test.xlsx
    • sheetname: string = 'sheet1'
tableExportExcel('.my-table', 'table表格.xlsx') // Export the table .xlsx of the .my-table element

jsonExportExcel

  • Json is exported to excel
  • 参数:
    • exportExcelOptions: { multiHeader?: [], header: [], data: any[][], filename?: string = 'excel-list', merges?: string[] = [], autoWidth: Boolean = false, bookType?: string = 'xlsx', sheetName?:string = 'sheet1', }
jsonExportExcel({
  header: ['Name', 'Age', 'Gender'],
  data: [
    ['Little King', '18', 'Male'],
    ['Little Lee', '20', 'Male'],
    ['Xiao Zhao', '21', 'male'],
    ['Xiao Zhang', '22', 'male'],
    ['Xiao Liu', '23', 'male'],
  ],
  fileName: 'Information on students in the second class of the third year',
  bookType: 'xlsx',
  sheetName: 'Student Information Form',
}) // Export information .xlsx for students in the second class of the third year

exportPdf

  • Export the pdf file
  • params:
    • src: Picture address
    • filename: filename
exportPdf('./a.jpg', 'xxx') // Export xxx .pdf

GitHub

欢迎PR