Skip to content

Commit fa54ff7

Browse files
committed
Merge remote-tracking branch 'origin/feat/multiply-sheets-export' into feat/excel-multiply-sheet-import
2 parents f5737ae + 64425fb commit fa54ff7

16 files changed

Lines changed: 341 additions & 87 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "feat: excel export multiply sheets\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vtable"
7+
}
8+
],
9+
"packageName": "@visactor/vtable",
10+
"email": "892739385@qq.com"
11+
}

docs/assets/api/en/SheetAPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Save all data as a configuration
7575
Export the current sheet to a file
7676

7777
```
78-
exportSheetToFile: (fileType: 'csv' | 'xlsx') => void
78+
exportSheetToFile: (fileType: 'csv' | 'xlsx', allSheets: boolean = true) => void
7979
```
8080

8181
### importFileToSheet(Function)

docs/assets/api/zh/SheetAPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ VTableSheet组件支持的方法如下:
7575
导出当前sheet到文件
7676

7777
```
78-
exportSheetToFile: (fileType: 'csv' | 'xlsx') => void
78+
exportSheetToFile: (fileType: 'csv' | 'xlsx', allSheets: boolean = true) => void
7979
```
8080

8181
### importFileToSheet(Function)

docs/assets/guide/en/plugin/table-export.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,10 @@ By default, the exported file will not be automatically downloaded, and you need
170170
By default, the exported file name is `export`; if you need to customize the file name, you can set `fileName` to the file name
171171

172172
## Usage Example
173-
Please refer to [table export](../../demo/export/table-export)
173+
Please refer to [table export](../../demo/export/table-export)
174+
175+
## vtable-sheet usage
176+
177+
In VTableSheet, you can refer to [VTableSheet export](../sheet/import_export).
178+
179+
Because the electronic spreadsheet needs to support exporting multiple sheets, so this plugin extends the interface ability to export all sheets, and specifically adds the exportMultipleVTablesToExcel method.
Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,70 @@
11
# Import and Export Capabilities
2-
The import and export functionality in VTable-Sheet relies on export plugins from VTable's plugin package @visactor/vtable-plugins.
2+
Import and export capabilities in VTable-Sheet rely on plugin packages from @visactor/vtable-plugins.
33

4-
Export plugin: @visactor/vtable-plugins/table-export-plugin, refer to the tutorial documentation: [Table Export](../plugin/table-export)
4+
Export plugin: @visactor/vtable-plugins/table-export-plugin, refer to the tutorial documentation: [table export](../plugin/table-export)
55

6-
Import plugin: @visactor/vtable-plugins/excel-import-plugin, refer to the tutorial documentation: [Table Import](../plugin/excel-import)
6+
Import plugin: @visactor/vtable-plugins/excel-import-plugin, refer to the tutorial documentation: [table import](../plugin/excel-import)
77

8-
Since VTable plugins only work on a single table instance, VTableSheet's current import and export capabilities are limited. It can only export data from the current sheet or import external data files into the current sheet. The export and import capabilities of VTableSheet will be expanded and improved in the future.
8+
If you want to modify the plugin configuration, you can configure the parameters of the import and export plugins through VTablePluginModules.
99

10-
If you want to modify the plugin configuration options, you can configure various parameters for the import and export plugins through VTablePluginModules.
10+
Import and export capabilities usually need to be used together with menu functionality, so you need to configure menu functionality, which can be referred to [menu functionality](./menu.md).
11+
12+
## Export sheet
13+
Export the current sheet, you can configure menuKey as VTableSheet.TYPES.MenuKey.EXPORT_CURRENT_SHEET_CSV to export a csv file, or configure menuKey as VTableSheet.TYPES.MenuKey.EXPORT_CURRENT_SHEET_XLSX to export an excel file.
14+
15+
Export excel file supports exporting all sheets, you can configure menuKey as VTableSheet.TYPES.MenuKey.EXPORT_ALL_SHEETS_XLSX to export an excel file.
16+
17+
Example:
18+
19+
```typescript
20+
mainMenu: {
21+
show: true,
22+
items: [
23+
......
24+
{
25+
name: 'Export',
26+
items: [
27+
{
28+
name: 'Export CSV',
29+
menuKey: TYPES.MainMenuItemKey.EXPORT_CURRENT_SHEET_CSV,
30+
description: 'Export current sheet data to csv'
31+
},
32+
{
33+
name: 'Export XLSX',
34+
menuKey: TYPES.MainMenuItemKey.EXPORT_CURRENT_SHEET_XLSX,
35+
description: 'Export current sheet data to xlsx'
36+
},
37+
{
38+
name: 'Export All Sheets',
39+
menuKey: TYPES.MainMenuItemKey.EXPORT_ALL_SHEETS_XLSX,
40+
description: 'Export all sheets to xlsx'
41+
}
42+
],
43+
description: 'Export current sheet data'
44+
}
45+
]
46+
}
47+
```
48+
49+
It also supports calling the export function through APIs, which can be referred to [API](../../api/SheetAPI#Methods.exportSheetToFile).
50+
51+
## Import sheet
52+
53+
Import sheet, you can configure menuKey as VTableSheet.TYPES.MenuKey.IMPORT to import a csv file or excel file.
54+
55+
Example:
56+
57+
```typescript
58+
mainMenu: {
59+
......
60+
items: [
61+
{
62+
name: 'Import',
63+
menuKey: VTableSheet.TYPES.MenuKey.IMPORT,
64+
description: 'Import data to current sheet'
65+
}
66+
]
67+
}
68+
```
69+
70+
It also supports calling the import function through APIs, which can be referred to [API](../../api/SheetAPI#Methods.importFileToSheet).

docs/assets/guide/zh/plugin/table-export.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,10 @@ const tableExportPlugin = new VTablePlugins.TableExportPlugin({
169169
默认情况下,导出文件名称为`export`;如果需要自定义文件名,可以设置`fileName`为文件名
170170

171171
## 用法示例
172-
可参考[表格导出](../../demo/export/table-export)
172+
可参考[表格导出](../../demo/export/table-export)
173+
174+
## vtable-sheet中使用
175+
176+
在VTableSheet中使用时,可以参考[VTableSheet导出](../sheet/import_export)
177+
178+
因为电子表格需要支持导出多个sheet,所以这个插件扩展导出所有sheet的接口能力,具体增加了exportMultipleVTablesToExcel方法。
Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,70 @@
11
# 导入导出能力
2-
VTable-Sheet中导入导出依赖VTable的插件@visactor/vtable-plugins中的导出插件包来实现的
2+
VTable-Sheet中导入导出依赖VTable的插件@visactor/vtable-plugins中的插件包来实现的
33

44
导出插件:@visactor/vtable-plugins/table-export-plugin ,参考教程文档:[表格导出](../plugin/table-export)
55

66
导入插件:@visactor/vtable-plugins/excel-import-plugin, 参考教程文档:[表格导入](../plugin/excel-import)
77

8-
因为VTable的插件只作用于单个表格实例,所以VTableSheet目前的导入导出能力不强,只能将当前sheet的数据导出,或将外部数据文件导入到当前sheet。后续会扩展完善 VTableSheet 的导出和导入能力
8+
如果想要修改插件的配置项,可以通过VTablePluginModules配置导入和导出插件的各个参数
99

10-
如果想要修改插件的配置项,可以通过VTablePluginModules配置导入和导出插件的各个参数。
10+
导入导出能力一般要配合菜单功能一起使用,所以需要配置菜单功能,具体可以参考[菜单功能](./menu.md)
11+
12+
## 导出sheet
13+
导出当前sheet,可以在mainMenu配menuKey为VTableSheet.TYPES.MenuKey.EXPORT_CURRENT_SHEET_CSV来导出csv文件,或者配menuKey为VTableSheet.TYPES.MenuKey.EXPORT_CURRENT_SHEET_XLSX来导出excel文件。
14+
15+
导出excel文件支持全部sheet导出,可以在mainMenu配menuKey为VTableSheet.TYPES.MenuKey.EXPORT_ALL_SHEETS_XLSX来导出excel文件。
16+
17+
具体如:
18+
19+
```typescript
20+
mainMenu: {
21+
show: true,
22+
items: [
23+
......
24+
{
25+
name: '导出',
26+
items: [
27+
{
28+
name: '导出csv',
29+
menuKey: TYPES.MainMenuItemKey.EXPORT_CURRENT_SHEET_CSV,
30+
description: '导出当前sheet数据到csv'
31+
},
32+
{
33+
name: '导出xlsx',
34+
menuKey: TYPES.MainMenuItemKey.EXPORT_CURRENT_SHEET_XLSX,
35+
description: '导出当前sheet数据到xlsx'
36+
},
37+
{
38+
name: '导出全部xlsx',
39+
menuKey: TYPES.MainMenuItemKey.EXPORT_ALL_SHEETS_XLSX,
40+
description: '导出所有sheet到xlsx'
41+
}
42+
],
43+
description: '导出当前sheet数据'
44+
}
45+
]
46+
}
47+
```
48+
49+
也支持通过API调用导出功能,具体可以参考[API](../../api/SheetAPI#Methods.exportSheetToFile)
50+
51+
## 导入sheet
52+
53+
导入sheet,可以在mainMenu配menuKey为VTableSheet.TYPES.MenuKey.IMPORT来导入csv文件或excel文件。
54+
55+
具体如:
56+
57+
```typescript
58+
mainMenu: {
59+
......
60+
items: [
61+
{
62+
name: '导入',
63+
menuKey: VTableSheet.TYPES.MenuKey.IMPORT,
64+
description: '导入数据到当前sheet'
65+
}
66+
]
67+
}
68+
```
69+
70+
也支持通过API调用导入功能,具体可以参考[API](../../api/SheetAPI#Methods.importFileToSheet)

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

0 commit comments

Comments
 (0)