VSeed, an elegant data composer, transforming complexity into simplicity.
!!!###!!!title=table export——VisActor/VTable tutorial documents!!!###!!!!!!###!!!description=
We encapsulated the table export plugin in `@visactor/vtable-plugins`, which can be used to easily export VTable tables as Excel and CSV files.
!!!###!!!
Table Export Plugin
We encapsulated the table export plugin in @visactor/vtable-plugins, which can be used to easily export VTable tables as Excel and CSV files.
Plugin Description
The plugin will add exportToCsv and exportToExcel methods to the table instance.
exportToCsv: export CSV file
exportToExcel: export Excel file
Plugin Configuration Introduction
The plugin initialization passes in the plugin configuration, and the configuration items are as follows:
exporttypeTableExportPluginOptions = {
exportExcelOptions?: ExportVTableToExcelOptions; // Excel export configuration
exportCsvOptions?: ExportVTableToCsvOptions; // CSV export configuration
exportOnIdle?: boolean; // Whether to export and download when idle, default false
};
Where exportExcelOptions and exportCsvOptions are export configurations, and exportOnIdle is whether to export and download when idle, default false.
The configuration items of exportExcelOptions and exportCsvOptions are as follows:
exporttype ExportVTableToCsvOptions = {
formatExportOutput?: (cellInfo: CellInfo) =>string | undefined;
escape?: boolean; // Whether to escape special symbols in strings to avoid interfering with CSV parsing, default true exportAllData?: boolean;
downloadFile?: boolean;
fileName?: string;
};
The following explains each configuration item:
ignoreIcon
By default, when a cell has an icon, the icon and text are treated as images and exported together; if you do not want to export the icon, you can set ignoreIcon to true and only output text
exportAllData
By default, only the data on the current page of the table is exported; if you have set pagination, if you want to export all data instead of the current page, you can set exportAllData to true
formatExportOutput
By default, when exporting the table, the text or image inside the exported cell is output to Excel; if you need to customize the exported content, you can set formatExportOutput to a function, the parameter of the function is the cell information, the return value of the function is the exported string, if the return value is undefined, the default export logic is followed
If you have further customization requirements for the export style, you can set formatExcelJSCell to a function, the parameter of the function is the cell information cellInfo and the cell object cellInExceljs of ExcelJS, the return value of the function is the cell object of ExcelJS, if the return value is undefined, the default export logic is followed. You can automatically set the cell properties of ExcelJS in the function, please refer to https://github.com/exceljs/exceljs?tab=readme-ov-file#styles
If you want to export the original record field value instead of the formatted value displayed in the table, you can use the table.getCellOriginValue(col,row) method to get the original value, and then assign it to cellInExceljs.value.
@visactor/vtable-export uses the exceljs library as a tool for exporting Excel files. If you need to further customize the Worksheet object of ExcelJS (for example, add page footers), you can set excelJSWorksheetCallback to a function, the parameter of the function is the Worksheet object of ExcelJS, and you can operate the Worksheet of ExcelJS in the function. Please refer to exceljs for the detailed usage of exceljs.
By default, when exporting the table, non-textual cells will export images; if you do not want to export images, you can set skipImageExportCellType to ['image', 'video', 'progressbar', 'sparkline', 'chart', 'custom', 'textWithIcon']
downloadFile
By default, the exported file will not be automatically downloaded, and you need to manually call the downloadFile method to download the file; if you want to automatically download the file, you can set downloadFile to true
fileName
By default, the exported file name is export; if you need to customize the file name, you can set fileName to the file name
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.