fix
This commit is contained in:
11
README.md
11
README.md
@@ -14,16 +14,23 @@
|
||||
## Installing
|
||||
|
||||
```shell
|
||||
npm install xe-utils vxe-table@next vxe-table-plugin-export-xlsx@next exceljs
|
||||
npm install vxe-table@next vxe-table-plugin-export-xlsx@next exceljs
|
||||
```
|
||||
|
||||
```javascript
|
||||
// ...
|
||||
import VXETable from 'vxe-table'
|
||||
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
|
||||
import ExcelJS from 'exceljs'
|
||||
// ...
|
||||
|
||||
VXETable.use(VXETablePluginExportXLSX)
|
||||
// 方式1:NPM 安装,注入 ExcelJS 对象
|
||||
VXETable.use(VXETablePluginExportXLSX, {
|
||||
ExcelJS
|
||||
})
|
||||
|
||||
// 方式2:CDN 安装,只要确保 window.ExcelJS 存在即可
|
||||
// VXETable.use(VXETablePluginExportXLSX)
|
||||
```
|
||||
|
||||
## Demo
|
||||
|
||||
15
index.ts
15
index.ts
@@ -1,8 +1,9 @@
|
||||
import XEUtils from 'xe-utils'
|
||||
import { VXETableCore, VxeTableConstructor, VxeTablePropTypes, VxeTableDefines, VxeGlobalInterceptorHandles } from 'vxe-table'
|
||||
import ExcelJS from 'exceljs'
|
||||
import type ExcelJS from 'exceljs'
|
||||
|
||||
let vxetable: VXETableCore
|
||||
let globalExcelJS: any
|
||||
|
||||
declare module 'vxe-table' {
|
||||
export namespace VxeTableDefines {
|
||||
@@ -213,7 +214,7 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams
|
||||
})
|
||||
}
|
||||
const exportMethod = () => {
|
||||
const workbook = new ExcelJS.Workbook()
|
||||
const workbook: ExcelJS.Workbook = new (globalExcelJS || (window as any).ExcelJS).Workbook()
|
||||
const sheet = workbook.addWorksheet(sheetName)
|
||||
workbook.creator = 'vxe-table'
|
||||
sheet.columns = sheetCols
|
||||
@@ -380,7 +381,7 @@ function importXLSX (params: VxeGlobalInterceptorHandles.InterceptorImportParams
|
||||
tableFields.push(field)
|
||||
}
|
||||
})
|
||||
const workbook = new ExcelJS.Workbook()
|
||||
const workbook: ExcelJS.Workbook = new (globalExcelJS || (window as any).ExcelJS).Workbook()
|
||||
const readerTarget = evnt.target
|
||||
if (readerTarget) {
|
||||
workbook.xlsx.load(readerTarget.result as ArrayBuffer).then(wb => {
|
||||
@@ -451,13 +452,17 @@ function handleExportEvent (params: VxeGlobalInterceptorHandles.InterceptorExpor
|
||||
* 基于 vxe-table 表格的扩展插件,支持导出 xlsx 格式
|
||||
*/
|
||||
export const VXETablePluginExportXLSX = {
|
||||
install (vxetable: VXETableCore) {
|
||||
install (vxetable: VXETableCore, options?: {
|
||||
ExcelJS?: any
|
||||
}) {
|
||||
// 检查版本
|
||||
if (!/^(4)\./.test(vxetable.version)) {
|
||||
console.error('[vxe-table-plugin-export-pdf] Version vxe-table 4.x is required')
|
||||
}
|
||||
|
||||
vxetable.setup({
|
||||
globalExcelJS = options ? options.ExcelJS : null
|
||||
|
||||
vxetable.config({
|
||||
export: {
|
||||
types: {
|
||||
xlsx: 0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vxe-table-plugin-export-xlsx",
|
||||
"version": "3.1.0",
|
||||
"version": "4.0.0",
|
||||
"description": "基于 vxe-table 表格的扩展插件,支持导出 xlsx 格式",
|
||||
"scripts": {
|
||||
"lib": "gulp build"
|
||||
@@ -51,8 +51,8 @@
|
||||
"sass": "^1.55.0",
|
||||
"typescript": "^4.6.4",
|
||||
"vue": "^3.3.4",
|
||||
"vxe-table": "^4.5.10",
|
||||
"xe-utils": "^3.5.13"
|
||||
"vxe-table": "^4.5.18",
|
||||
"xe-utils": "^3.5.18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vxe-table": "^4.5.0"
|
||||
|
||||
4
types/index.d.ts
vendored
4
types/index.d.ts
vendored
@@ -4,7 +4,9 @@ import { VXETableCore } from 'vxe-table'
|
||||
* 基于 vxe-table 表格的扩展插件,支持导出 xlsx 格式
|
||||
*/
|
||||
export declare const VXETablePluginExportXLSX: {
|
||||
install (vxetable: VXETableCore): void
|
||||
install (vxetable: VXETableCore, options?: {
|
||||
ExcelJS?: any
|
||||
}): void
|
||||
}
|
||||
|
||||
export default VXETablePluginExportXLSX
|
||||
|
||||
Reference in New Issue
Block a user