0.0.4 • Published 1 year ago

mexcel v0.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

mxlsx插件使用文档

npm i mexcel

excel导入

方法描述类型
importExcel导入 具体参数查看下方IExcelImportConfigIExcelImportConfig
参数描述类型必填可选值默认值
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 时才生效booleantrue | falsetrue
onProgress导入文件进度(event: ProgressEvent) => void----

excel导出

方法描述类型
exportExcel导出(excelData: IExcel, path?: string, success?: () => void, fail?: (err: unknown) => void) => void
参数说明
参数描述类型必填可选值默认值
fileName文件名string--excel
fileExtention文件格式stringxlsx | xlsxlsx
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数据格式string0 | 0.00% | 0.0% | 0.00%;\(0.00%\);\-;@ | m/dd/yy0
参数描述类型必填可选值默认值
bold粗细booleantrue | falsefalse
color字体颜色 具体参数查看下方颜色参数CellStyleColor----
italic斜体booleantrue | falsefalse
name字体string--Calibri
sz字体大小number----
strike删除线booleantrue | falsefalse
underline下划线booleantrue | falsefalse
vertAlign上下标string"superscript" | "subscript"null
参数描述类型必填可选值默认值
horizontal横向对齐stringleft | center | rightleft
vertical纵向对齐stringtop | center | bottombottom
textRotation文字旋转number0 - 180 | 2550
wrapText是否换行booleantrue | falsefalse
参数描述类型必填可选值默认值
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模式stringsolid | nonesolid
参数描述类型必填可选值默认值
s开始单元格 具体参数查看下方表格位置参数CellAddress----
e结束单元格 具体参数查看下方表格位置参数CellAddress----
参数描述类型必填可选值默认值
c列数number0 - max--
r行数number0 - max--
参数描述类型必填可选值默认值
hidden是否隐藏行booleantrue | falsefalse
hpx行高 屏幕像素高度number0 - max--
hpt行高 以点为单位的高度number0 - max--
level分组折叠number----
参数描述类型必填可选值默认值
hidden是否隐藏列booleantrue | falsefalse
width列宽 最大数字宽度中的宽度number0 - max--
wpx列宽 Excel的“最大数字宽度”中的宽度,width256是整数*number0 - max--
wch列宽 字符宽度number0 - max--
level分组折叠number----
MDW列宽 Excel 的“最大数字宽度”单位,始终为整数number0 - max--
参数描述类型必填可选值默认值
rgb颜色值 hex值不要带#号string----
theme主题色 theme与rgb不同时存在,theme覆盖rgbnumber----
tint透明度 在theme存在是生效-1.0 - 1.0----
描述类型必填可选值默认值
边框样式BorderTypedashDot | 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);
0.0.4

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago