{{ target: sheet-api }}
VTableSheet instance supports the following methods:
Activate the specified sheet
activateSheet: (sheetKey: string) => void
Add a new sheet
addSheet: (sheet: ISheetDefine) => void
Remove the specified sheet
removeSheet: (sheetKey: string) => void
Get the number of sheets
getSheetCount: () => number
Get the definition of the specified sheet
getSheet: (sheetKey: string) => ISheetDefine | null
Get all sheet definitions
getAllSheets: () => ISheetDefine[]
Get the currently active WorkSheet instance
getActiveSheet: () => WorkSheet | null
Save all data as a configuration
saveToConfig: () => IVTableSheetOptions
Export the current sheet to a file
exportSheetToFile: (fileType: 'csv' | 'xlsx', allSheets: boolean = true) => void
Import a file to the current sheet
/** clearExisting Whether to clear existing sheets (default true means replace mode). Set false to append mode */
importFileToSheet: (options: { clearExisting?: boolean } = { clearExisting: true }) => void
Export the data of the specified sheet
exportData: (sheetKey: string) => any[][]
Export the data of all sheets
exportAllData: () => any[][]
Adjust the size of the table
resize: () => void
Release resources
release: () => void
Get the container element
getContainer: () => HTMLElement
Get the formula manager
getFormulaManager: () => FormulaManager
Sheet event list, you can listen to the required events according to the actual needs, to achieve customized business.
Specific usage:
import { WorkSheetEventType } from '@visactor/vtable-sheet';
// Use WorkSheet instance to listen to events
worksheet.on(WorkSheetEventType.CELL_CLICK, (args) => {
console.log('Cell selected:', args);
});
Supported event types:
export enum WorkSheetEventType {
// Cell event
CELL_CLICK = 'cell-click',
CELL_VALUE_CHANGED = 'cell-value-changed',
// Selection range event
SELECTION_CHANGED = 'selection-changed',
SELECTION_END = 'selection-end'
}
If you want to listen to the events of the VTable component, you can get the instance of VTable through the interface, and then listen to the events through the instance Specific usage:
const tableInstance = sheetInstance.activeWorkSheet.tableInstance;// Get the instance of the active sheet
tableInstance.on('mousedown_cell', (args) => console.log(CLICK_CELL, args));
Cell click event
Event return parameters:
{
/** Row index */
row: number;
/** Column index */
col: number;
/** Cell content */
value?: CellValue;
/** Cell DOM element */
cellElement?: HTMLElement;
/** Original event object */
originalEvent?: MouseEvent | KeyboardEvent;
}
Cell value change event
Event return parameters:
{
/** Row index */
row: number;
/** Column index */
col: number;
/** New value */
newValue: CellValue;
/** Old value */
oldValue: CellValue;
/** Cell DOM element */
cellElement?: HTMLElement;
/** Whether caused by user operation */
isUserAction?: boolean;
/** Whether caused by formula calculation */
isFormulaCalculation?: boolean;
}
Selection range change event
Event return parameters:
{
/** Selection range */
ranges?: Array<{
start: {
row: number;
col: number;
};
end: {
row: number;
col: number;
};
}>;
/** Selected cell data */
cells?: Array<
Array<{
row: number;
col: number;
value?: CellValue;
}>
>;
/** Original event object */
originalEvent?: MouseEvent | KeyboardEvent;
}
Selection end event (triggered when drag selection is completed)
Event return parameters:
{
/** Selection range */
ranges?: Array<{
start: {
row: number;
col: number;
};
end: {
row: number;
col: number;
};
}>;
/** Selected cell data */
cells?: Array<
Array<{
row: number;
col: number;
value?: CellValue;
}>
>;
/** Original event object */
originalEvent?: MouseEvent | KeyboardEvent;
}