Skip to content

Commit 64425fb

Browse files
committed
fix: supplement _exportMutipleTablesToExcel for vtableSheet instance
1 parent b6fa264 commit 64425fb

4 files changed

Lines changed: 34 additions & 14 deletions

File tree

packages/vtable-plugins/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ export * from './table-series-number';
1919
export * from './context-menu';
2020
export * from './filter';
2121
export * from './table-export';
22-
export * from './table-export/index';
2322
export * from './auto-fill';

packages/vtable-plugins/src/table-export.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { pluginsDefinition, ListTable } from '@visactor/vtable';
22
import { TABLE_EVENT_TYPE } from '@visactor/vtable';
33
import type { ExportVTableToCsvOptions, ExportVTableToExcelOptions } from './table-export/index';
4-
import { exportVTableToCsv, exportVTableToExcel, downloadCsv, downloadExcel } from './table-export/index';
4+
import {
5+
exportVTableToCsv,
6+
exportVTableToExcel,
7+
downloadCsv,
8+
downloadExcel,
9+
exportMultipleVTablesToExcel
10+
} from './table-export/index';
511

612
// // 扩展ListTable接口以包含导出方法
713
// declare module '@visactor/vtable' {
@@ -65,6 +71,20 @@ export class TableExportPlugin implements pluginsDefinition.IVTablePlugin {
6571
}
6672
return exportVTableToExcel(this.table, options, this.pluginOptions.exportOnIdle);
6773
};
74+
if ((this.table as any).__vtableSheet) {
75+
// 给VTableSheet实例添加导出所有sheet到Excel的方法
76+
if (!((this.table as any).__vtableSheet as any)._exportMutipleTablesToExcel) {
77+
((this.table as any).__vtableSheet as any)._exportMutipleTablesToExcel = async (
78+
tables: Array<{ table: any; name?: string }>
79+
) => {
80+
const buffer = (await exportMultipleVTablesToExcel(
81+
tables,
82+
this.pluginOptions.exportExcelOptions
83+
)) as ArrayBuffer;
84+
await downloadExcel(buffer, this.pluginOptions.exportExcelOptions.fileName || 'vtable-sheet-export');
85+
};
86+
}
87+
}
6888
}
6989
}
7090

packages/vtable-sheet/src/components/vtable-sheet.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import { formulaEditor } from '../formula/formula-editor';
1414
import { CellHighlightManager } from '../formula/cell-highlight-manager';
1515
import type { TYPES } from '@visactor/vtable';
1616
import { MenuManager } from '../managers/menu-manager';
17-
import { exportMultipleVTablesToExcel, downloadExcel } from '@visactor/vtable-plugins';
18-
import type { ExportVTableToExcelOptions } from '@visactor/vtable-plugins';
1917
import { FormulaUIManager } from '../formula/formula-ui-manager';
2018
import { SheetTabEventHandler } from './sheet-tab-event-handler';
2119

@@ -755,22 +753,23 @@ export default class VTableSheet {
755753
}
756754
}
757755
}
758-
/** 导出所有sheet到一个Excel文件 */
759-
async exportAllSheetsToExcel(fileName?: string, options?: ExportVTableToExcelOptions): Promise<void> {
756+
exportAllSheetsToExcel(): void {
757+
this.initAllSheetInstances();
758+
const allDefines = this.sheetManager.getAllSheets();
759+
const tables = allDefines.map(def => {
760+
const inst = this.workSheetInstances.get(def.sheetKey)!;
761+
return { table: inst.tableInstance as any, name: def.sheetTitle || def.sheetKey };
762+
});
763+
(this as any)._exportMutipleTablesToExcel?.(tables); //这个方法是在vtable-plugins中添加的,table-export插件在VTableSheet实例上添加了导出所有sheet到Excel的方法
764+
}
765+
initAllSheetInstances(): void {
760766
const allDefines = this.sheetManager.getAllSheets();
761-
const activeKey = this.sheetManager.getActiveSheet()?.sheetKey;
762767
allDefines.forEach(def => {
763768
if (!this.workSheetInstances.has(def.sheetKey)) {
764769
const instance = this.createWorkSheetInstance(def);
765770
this.workSheetInstances.set(def.sheetKey, instance);
766771
}
767772
});
768-
const tables = allDefines.map(def => {
769-
const inst = this.workSheetInstances.get(def.sheetKey)!;
770-
return { table: inst.tableInstance as any, name: def.sheetTitle || def.sheetKey };
771-
});
772-
const buffer = (await exportMultipleVTablesToExcel(tables, options)) as ArrayBuffer;
773-
await downloadExcel(buffer, fileName || 'vtable-sheet-export');
774773
}
775774
/** 导入文件到当前sheet */
776775
async importFileToSheet(): Promise<ImportResult | void> {

packages/vtable-sheet/src/core/WorkSheet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export class WorkSheet extends EventTarget implements IWorkSheetAPI {
151151
this.element.classList.add('vtable-excel-cursor');
152152
// 获取事件总线
153153
this.eventBus = (this.tableInstance as any).eventBus;
154+
// 在 tableInstance 上设置 VTableSheet 引用,方便插件访问
155+
(this.tableInstance as any).__vtableSheet = this.vtableSheet;
154156
}
155157

156158
/**
@@ -1002,7 +1004,7 @@ export class WorkSheet extends EventTarget implements IWorkSheetAPI {
10021004

10031005
// 如果是公式,设置公式;否则设置普通值
10041006
if (FormulaPasteProcessor.needsFormulaAdjustment(value)) {
1005-
this.setCellFormula(targetRow, targetCol, value);
1007+
this.setCellFormula(targetRow, targetCol, value as string);
10061008
} else {
10071009
this.setCellValue(targetRow, targetCol, value);
10081010
}

0 commit comments

Comments
 (0)