FWorkbookSheetsTableMixin
| packages | @univerjs/sheets-table |
|---|
APIs
addTable
Add table
Signature
addTable(subUnitId: string, tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise<string | undefined>Parameters
subUnitId(string) — The sub unit idtableName(string) — The table namerangeInfo(ITableRange) — The table range informationtableId(string) — The table idoptions(ITableOptions) — The table options
Returns
- (
Promise<string | undefined>) — The table id
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Insert a table in the range B2:F11
const fRange = fWorksheet.getRange('B2:F11')
const id = await fWorkbook.addTable(
fWorksheet.getSheetId(),
'name-1',
fRange.getRange(),
'id-1',
{
tableStyleId: 'table-default-4',
},
)
if (id) {
const tableInfo = fWorkbook.getTableInfo(id)
console.log('debugger tableInfo', tableInfo)
}getTableInfo
Get table information
Signature
getTableInfo(tableId: string): ITableInfoWithUnitId | undefinedParameters
tableId(string) — The table id
Returns
- (
ITableInfoWithUnitId | undefined) — The table information
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Insert a table in the range B2:F11
const fRange = fWorksheet.getRange('B2:F11')
const success = await fWorksheet.addTable(
'name-1',
fRange.getRange(),
'id-1',
{
tableStyleId: 'table-default-4',
},
)
if (success) {
const tableInfo = fWorkbook.getTableInfo('id-1')
console.log('debugger tableInfo', tableInfo)
}getTableInfoByName
Get table information by name
Signature
getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefinedParameters
tableName(string) — The table name
Returns
- (
ITableInfoWithUnitId | undefined) — The table information
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Insert a table in the range B2:F11
const fRange = fWorksheet.getRange('B2:F11')
const success = await fWorksheet.addTable(
'name-1',
fRange.getRange(),
'id-1',
{
tableStyleId: 'table-default-4',
},
)
if (success) {
const tableInfo = fWorkbook.getTableInfoByName('name-1')
console.log('debugger tableInfo', tableInfo)
}getTableList
Get table list
Signature
getTableList(): ITableInfoWithUnitId[]Returns
- (
ITableInfoWithUnitId[]) — The table list
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const tables = fWorkbook.getTableList()
console.log('debugger tables', tables)removeTable
Remove table
Signature
removeTable(tableId: string): Promise<boolean>Parameters
tableId(string) — The table id
Returns
- (
Promise<boolean>) — The result of remove table
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const tableInfo = fWorkbook.getTableInfo('id-1')
console.log('debugger tableInfo', tableInfo)
if (tableInfo) {
// Remove the table with the specified id
await fWorkbook.removeTable('id-1')
}setTableFilter
set table filter
Signature
setTableFilter(tableId: string, column: number, filter: ITableFilterItem | undefined): Promise<boolean>Parameters
tableId(string) — The table idcolumn(number) — The column index, starting from 0.filter(ITableFilterItem | undefined) — The filter item
Returns
- (
Promise<boolean>) — The result of set table filter
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Insert a table in the range B2:F11
const fRange = fWorksheet.getRange('B2:F11')
const success = await fWorksheet.addTable(
'name-1',
fRange.getRange(),
'id-1',
{
tableStyleId: 'table-default-4',
},
)
if (success) {
// Set the filter for the second column
await fWorkbook.setTableFilter('id-1', 1, {
filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,
filterInfo: {
conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,
compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,
expectedValue: 10,
},
})
const tableInfo = fWorkbook.getTableInfo('id-1')
console.log('debugger tableInfo', tableInfo)
}