Excel export
The @visactor/vtable-export
package is a tool packaged for VTable table export. It supports export in both CSV and Excel formats.
Usage
import
First, you need to install the @visactor/vtable
and @visactor/vtable-export
packages in your application, then introduce them in your code to generate a table instance and export it:
exportVTableToExcel
: Table output tool, outputs table instances as an ArrayBuffer in Excel format; option is an optional parameter, see below for configuration itemsdownloadExcel
: Download tool to download the ArrayBuffer in Excel format as a file in the browser environment- If it is a server environment, you can process the Excel format ArrayBuffer converted by
exportVTableToExcel
yourself. - The excel export function is currently being improved. Currently, it only supports the export of text-type cells, and will support more types such as sparkline in the future.
Referencedemo
umd
You can also directly introduce the umd product of the @visactor/vtable-export
package in HTML:
Find the corresponding tool in the global variable VTable.export
and use the same method as above:
Options
ignoreIcon
By default, when the cell has an icon, the icon and text will be treated as an image when exporting. If you do not need to export the icon, you can set ignoreIcon
to true, and only the text will be output.
formatExportOutput
By default, when exporting, the text or image inside the exported cell will be output to Excel. If you need to customize the export content, you can set formatExportOutput
to a function, and the return value of the function is the exported string. If the return value is undefined
, the default export logic will be processed.
formatExcelJSCell
If you need to further customize the export style, you can set formatExcelJSCell
to a function. The function parameters are cell information cellInfo
and ExcelJS cell objects cellInExceljs
. The function return value is the ExcelJS cell object. If undefined
is returned, the default export logic is used. You can automatically set ExcelJS cell properties in the function. For details, please refer to https://github.com/exceljs/exceljs?tab=readme-ov-file#styles
Here is an example of specifying the number format for the first column as a percentage:
If you want to export the original record field value instead of the format displayed in the table, you can use the table.getCellOriginValue(col,row) method to get it and assign it to cellInExceljs.value.
excelJSWorksheetCallback
@visactor/vtable-export
uses the exceljs
library as a tool for exporting Excel files. If you need to further customize the ExcelJS Worksheet object (such as adding a page footer), you can set excelJSWorksheetCallback
to a function whose parameter is the ExcelJS Worksheet object. You can operate the ExcelJS Worksheet in the function.For detailed usage of exceljs
, please refer to exceljs