Table

Headless supported

A table turns a range into a named object that can be managed as a whole. It keeps its own style, header row, and filters. After it is created, the Facade API can restyle it, filter it, resize it, or remove it.

Plugin mode

Installation

Shell
pnpm add @univerjs/sheets-table @univerjs/sheets-table-ui

Usage

TypeScript
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { UniverSheetsTablePlugin } from '@univerjs/sheets-table'import { UniverSheetsTableUIPlugin } from '@univerjs/sheets-table-ui'import SheetsTableUIEnUS from '@univerjs/sheets-table-ui/locale/en-US'import '@univerjs/sheets-table-ui/lib/index.css'import '@univerjs/sheets-table/facade'const univer = new Univer({  locale: LocaleType.EN_US,  locales: {    [LocaleType.EN_US]: mergeLocales(      SheetsTableUIEnUS,     ),  },})univer.registerPlugin(UniverSheetsTablePlugin)univer.registerPlugin(UniverSheetsTableUIPlugin)

Mobile support

Set up the mobile editor first. In the plugin-mode setup on this page, replace the desktop registration below with its mobile export from the same package, before opening a document. Keep the model plugins, styles, locales, and Facade imports, and do not register both variants.

PackageDesktop registrationMobile registration
@univerjs/sheets-table-uiUniverSheetsTableUIPluginUniverSheetsTableMobileUIPlugin

Preset mode

Installation

Shell
pnpm add @univerjs/preset-sheets-table

Usage

TypeScript
import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core'import UniverPresetSheetsCoreEnUS from '@univerjs/preset-sheets-core/locales/en-US'import { UniverSheetsTablePreset } from '@univerjs/preset-sheets-table'import UniverPresetSheetsTableEnUS from '@univerjs/preset-sheets-table/locales/en-US'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-sheets-core/lib/index.css'import '@univerjs/preset-sheets-table/lib/index.css'const { univerAPI } = createUniver({  locale: LocaleType.EN_US,  locales: {    [LocaleType.EN_US]: mergeLocales(      UniverPresetSheetsCoreEnUS,      UniverPresetSheetsTableEnUS,     ),  },  presets: [    UniverSheetsCorePreset(),    UniverSheetsTablePreset(),   ],})

Facade API

The full Facade API type definitions are in FacadeAPI.

Importing

Plugin mode note

Only plugin mode requires manually importing the Facade package. Preset mode already includes the corresponding Facade package, so no additional import is required.

TypeScript
import '@univerjs/sheets-table/facade'

Insert table

  • FWorkbook.addTable inserts a table into a specific worksheet of the workbook.
  • FWorksheet.addTable inserts a table into the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable(  'name-1',  fRange.getRange(),  'id-1',  {    tableStyleId: 'table-default-4',    columns: [      { id: 'col-1', displayName: 'Column 1' },    ],    filters: [      {        filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,        filterInfo: {          conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,          compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,          expectedValue: 2,        },      },    ],  },)if (success) {  const tableInfo = fWorkbook.getTableInfo('id-1')  console.log('debugger tableInfo', tableInfo)}

Get table

  • FWorkbook.getTableList returns all tables in the workbook.
  • FWorksheet.getSubTableInfos returns all tables in the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const tables = fWorkbook.getTableList()console.log('debugger tables', tables)
  • FWorkbook.getTableInfo returns table information by table ID.
  • FWorkbook.getTableInfoByName returns table information by table name.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Insert a table in the range B2:F11const 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)}
  • FWorksheet.getTableByCell returns table information by cell position.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const cellB2 = fWorksheet.getRange('B2')const row = cellB2.getRow()const column = cellB2.getColumn()console.log('debugger tableInfo', fWorksheet.getTableByCell(row, column))// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable(  'name-1',  fRange.getRange(),  'id-1',  {    tableStyleId: 'table-default-4',  },)console.log('debugger tableInfo2', fWorksheet.getTableByCell(row, column))

Set filter

  • FWorkbook.setTableFilter sets the filter for a table in the workbook.
  • FWorksheet.setTableFilter sets the filter for a table in the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Insert a table in the range B2:F11const 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 fWorksheet.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)}
  • FWorksheet.resetFilter resets the filter for a table in the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Insert a table in the range B2:F11const 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 fWorksheet.setTableFilter('id-1', 1, {    filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,    filterInfo: {      conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,      compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,      expectedValue: 10,    },  })  // Reset the filter for the second column after 3 seconds  setTimeout(async () => {    await fWorksheet.resetFilter('id-1', 1)  }, 3000)  const tableInfo = fWorkbook.getTableInfo('id-1')  console.log('debugger tableInfo', tableInfo)}

Modify/delete table

  • FWorkbook.removeTable removes a table from the workbook.
  • FWorksheet.removeTable removes a table from the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const tableInfo = fWorkbook.getTableInfo('id-1')console.log('debugger tableInfo', tableInfo)if (tableInfo) {  // Remove the table with the specified id  await fWorksheet.removeTable('id-1')}
  • FWorksheet.setTableRange moves or resizes a table in the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable(  'name-1',  fRange.getRange(),  'id-1',  {    tableStyleId: 'table-default-4',  },)if (success) {  // Update the table range to B2:F21 after 3 seconds  setTimeout(async () => {    const newRange = fWorksheet.getRange('B2:F21')    await fWorksheet.setTableRange('id-1', newRange.getRange())    const tableInfo = fWorkbook.getTableInfo('id-1')    console.log('debugger tableInfo', tableInfo)  }, 3000)}
  • FWorksheet.setTableName renames a table in the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable(  'name-1',  fRange.getRange(),  'id-1',  {    tableStyleId: 'table-default-4',  },)if (success) {  // Update the table name after 3 seconds  setTimeout(async () => {    await fWorksheet.setTableName('id-1', 'new-name')    const tableInfo = fWorkbook.getTableInfo('id-1')    console.log('debugger tableInfo', tableInfo)  }, 3000)}

Add table theme

  • FWorksheet.addTableTheme adds a theme to a table in the worksheet.
TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable(  'name-1',  fRange.getRange(),  'id-1',  {    tableStyleId: 'table-default-4',  },)if (success) {  await fWorksheet.addTableTheme('id-1', {    name: 'table-custom-1',    headerRowStyle: {      bg: {        rgb: '#145f82',      },    },    firstRowStyle: {      bg: {        rgb: '#c0e4f5',      },    },  })  const tableInfo = fWorkbook.getTableInfo('id-1')  console.log('debugger tableInfo', tableInfo)}

Move a table with its cells

If you move a cell range that contains a whole table, the table moves with it, either within the same worksheet or to another worksheet in the same workbook. The range must include the header row and all table rows. The table keeps its identity, name, style, column metadata, and filters, and structured references follow it to the new location. The destination must be editable, inside the worksheet bounds, and must not overlap another table. Undo and redo restore both the cells and the table metadata.

How is this guide?

© 2026 DreamNum Co., Ltd.