Skip to content

基于已有的xlsx插件封装excel导入导出功能,使得使用更方便,更符合自己的使用风格

Notifications You must be signed in to change notification settings

moneyinto/mxlsx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mxlsx插件使用文档

npm i mexcel

excel导入

方法 描述 类型
importExcel 导入 具体参数查看下方IExcelImportConfig IExcelImportConfig
IExcelImportConfig
参数 描述 类型 必填 可选值 默认值
file 文件 File | Blob -- --
keys 导入数据key值 "A" | number | string[] -- --
keyRow 读取excel表格中某行数据作为key值, keys 存在的情况下 keyRow 不生效 number -- --
dataRow 读取excel表格中从某行开始 number -- 0
customKey 是否采用自定义key keys、keyRow 和 dataRow 只有在 customKey 为 true 时才生效 boolean true | false true
onProgress 导入文件进度 (event: ProgressEvent) => void -- --

excel导出

方法 描述 类型
exportExcel 导出 (excelData: IExcel, path?: string, success?: () => void, fail?: (err: unknown) => void) => void
参数说明
参数 描述 类型 必填 可选值 默认值
fileName 文件名 string -- excel
fileExtention 文件格式 string xlsx | xls xlsx
sheets 工作表数据工作表参数 ISheet -- --
  • 工作表参数
参数 描述 类型 必填 可选值 默认值
title 表格标题,自动合并单元格 string -- --
titleStyle 表格标题样式 具体参数查看下方单元格样式参数 在title存在的情况才生效 CellStyle -- --
tHeaders 表格表头 可以配置多表头,自动合并单元格 INSArr[] -- --
tHeaderStyle 表格表头样式 具体参数查看下方单元格样式参数 在tHeaders存在的情况才生效 CellStyle -- --
table 表格数据 ITable[] -- --
cols 列样式配置 具体参数查看下方列样式参数 ColInfo[] -- --
titleRow 表格标题行样式配置 行样式参数 在title存在的情况才生效 RowInfo -- --
headerRows 列样式配置 具体参数查看下方行样式参数 在tHeaders存在的情况才生效 RowInfo[] -- --
row 行样式配置 具体参数查看下方行样式参数 RowInfo -- --
merges 单元格合并配置 具体参数查看下方合并参数 Range[] -- --
keys 表格数据key值描述 参数数据影响标题和表头的自动合并 INSArr -- --
sheetName 工作表名字 string -- sheet + 索引值
globalStyle 单元格全局样式 具体参数查看下方单元格样式参数 CellStyle -- --
cellStyle 具体单元格自定义样式 具体参数查看下方单元格样式参数 ICellStyle -- --
  • 单元格样式参数
参数 描述 类型 必填 可选值 默认值
font 字体样式 具体参数查看下方字体样式参数 CellStyle.font -- --
alignment 对齐方式 具体参数查看下方对齐方式参数 CellStyle.alignment -- --
border 边框样式 具体参数查看下方边框样式参数 CellStyle.border -- --
fill 背景样式 具体参数查看下方背景样式参数 CellStyle.fill -- --
numFmt 数据格式 string 0 | 0.00% | 0.0% | 0.00%;\(0.00%\);\-;@ | m/dd/yy 0
  • 字体样式参数
参数 描述 类型 必填 可选值 默认值
bold 粗细 boolean true | false false
color 字体颜色 具体参数查看下方颜色参数 CellStyleColor -- --
italic 斜体 boolean true | false false
name 字体 string -- Calibri
sz 字体大小 number -- --
strike 删除线 boolean true | false false
underline 下划线 boolean true | false false
vertAlign 上下标 string "superscript" | "subscript" null
  • 对齐方式参数
参数 描述 类型 必填 可选值 默认值
horizontal 横向对齐 string left | center | right left
vertical 纵向对齐 string top | center | bottom bottom
textRotation 文字旋转 number 0 - 180 | 255 0
wrapText 是否换行 boolean true | false false
  • 边框样式参数
参数 描述 类型 必填 可选值 默认值
top 上边 具体参数查看下方颜色参数 边框属性参数 { color: CellStyleColor; style?: BorderType } -- --
bottom 下边 { color: CellStyleColor; style?: BorderType } -- --
left 左边 { color: CellStyleColor; style?: BorderType } -- --
right 右边 { color: CellStyleColor; style?: BorderType } -- --
diagonal 对角线 { color: CellStyleColor; style?: BorderType; diagonalUp?: boolean; diagonalDown?: boolean } -- --
  • 背景样式参数
参数 描述 类型 必填 可选值 默认值
bgColor 背景色 具体参数查看下方颜色参数 CellStyleColor -- --
fgColor 前景色 具体参数查看下方颜色参数 CellStyleColor -- --
patternType 模式 string solid | none solid
  • 合并参数
参数 描述 类型 必填 可选值 默认值
s 开始单元格 具体参数查看下方表格位置参数 CellAddress -- --
e 结束单元格 具体参数查看下方表格位置参数 CellAddress -- --
  • 表格位置参数
参数 描述 类型 必填 可选值 默认值
c 列数 number 0 - max --
r 行数 number 0 - max --
  • 行样式参数
参数 描述 类型 必填 可选值 默认值
hidden 是否隐藏行 boolean true | false false
hpx 行高 屏幕像素高度 number 0 - max --
hpt 行高 以点为单位的高度 number 0 - max --
level 分组折叠 number -- --
  • 列样式参数
参数 描述 类型 必填 可选值 默认值
hidden 是否隐藏列 boolean true | false false
width 列宽 最大数字宽度中的宽度 number 0 - max --
wpx 列宽 Excel的“最大数字宽度”中的宽度,width256是整数* number 0 - max --
wch 列宽 字符宽度 number 0 - max --
level 分组折叠 number -- --
MDW 列宽 Excel 的“最大数字宽度”单位,始终为整数 number 0 - max --
  • 颜色参数
参数 描述 类型 必填 可选值 默认值
rgb 颜色值 hex值不要带#号 string -- --
theme 主题色 theme与rgb不同时存在,theme覆盖rgb number -- --
tint 透明度 在theme存在是生效 -1.0 - 1.0 -- --
  • 边框属性参数
描述 类型 必填 可选值 默认值
边框样式 BorderType dashDot | dashDotDot | dashed | dotted | hair | medium | mediumDashDot | mediumDashDotDot | mediumDashed | slantDashDot | thick | thin --
import { exportExcel, IExcel } from "mexcel";

const excelData: IExcel = {
    sheets: [
        {
            title: "学生列表",
            tHeaders: [["学号", "姓名", "班级", "考试成绩"], ["", "", "", "语文", "数学", "英语"]],
            merges: [
                {
                    s: { c: 0, r: 1 },
                    e: { c: 0, r: 2 }
                },
                {
                    s: { c: 1, r: 1 },
                    e: { c: 1, r: 2 }
                },
                {
                    s: { c: 2, r: 1 },
                    e: { c: 2, r: 2 }
                },
                {
                    s: { c: 3, r: 1 },
                    e: { c: 5, r: 1 }
                }
            ],
            table: [
                {
                    no: "1",
                    name: "李浩",
                    class: "二年级2班",
                    yuwen: 93,
                    shuxue: 95,
                    yingyu: 88
                },
                {
                    no: "2",
                    name: "王明",
                    class: "二年级1班",
                    yuwen: 89,
                    shuxue: 99,
                    yingyu: 90
                }
            ],
            cols: [
                {
                    wpx: 50
                },
                {
                    wpx: 100
                },
                {
                    wpx: 200
                },
                {
                    wpx: 50
                },
                {
                    wpx: 50
                },
                {
                    wpx: 50
                }
            ],
            titleRow: {
                hpx: 60
            },
            headerRows: [
                {
                    hpx: 40
                },
                {
                    hpx: 40
                }
            ],
            row: {
                hpx: 30
            },
            keys: ["no", "name", "class", "yuwen", "shuxue", "yingyu"],
            sheetName: "学生列表",
            globalStyle: {
                font: {
                    sz: 18
                },
                alignment: {
                    horizontal: "center",
                    vertical: "center",
                    wrapText: true
                },
                border: {
                    top: { style: "thin", color: {} },
                    right: { style: "thin", color: {} },
                    bottom: { style: "thin", color: {} },
                    left: { style: "thin", color: {} }
                }
            },
            titleStyle: {
                font: {
                    sz: 22,
                    color: {
                        rgb: "f60000"
                    }
                },
                alignment: {
                    horizontal: "center",
                    vertical: "center",
                    wrapText: true
                },
                border: {
                    top: { style: "thin", color: {} },
                    right: { style: "thin", color: {} },
                    bottom: { style: "thin", color: {} },
                    left: { style: "thin", color: {} }
                }
            }
        }
    ],
    fileName: "学生信息"
};

exportExcel(excelData);

About

基于已有的xlsx插件封装excel导入导出功能,使得使用更方便,更符合自己的使用风格

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published