Table
Enhanced tables provide full table editing in Univer Docs: cell styling, borders, row and column changes, and filling a table from data.
Introduction
In Univer Docs, tables support the following operations:
- Create a table with the dimensions you specify.
- Add, delete, and move rows and columns.
- Apply borders, backgrounds, and text formatting to cells.
- Merge and split cells to build complex layouts.
Plugin mode
Installation
pnpm add @univerjs-pro/docs-table @univerjs-pro/docs-table-uinpm install @univerjs-pro/docs-table @univerjs-pro/docs-table-uiyarn add @univerjs-pro/docs-table @univerjs-pro/docs-table-uibun add @univerjs-pro/docs-table @univerjs-pro/docs-table-uiUsage
import { UniverDocsTablePlugin } from '@univerjs-pro/docs-table'import { UniverDocsTableUIPlugin } from '@univerjs-pro/docs-table-ui'import DocsTableUIEnUS from '@univerjs-pro/docs-table-ui/locale/en-US'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import '@univerjs-pro/docs-table-ui/lib/index.css'const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DocsTableUIEnUS, ), },})univer.registerPlugin(UniverDocsTablePlugin)univer.registerPlugin(UniverDocsTableUIPlugin)If you use a commercial license, configure it as described in Using License in Client.
Mobile support
Configure the mobile editor first. In the plugin-mode setup described on this page, replace the desktop registration below with the mobile export from the same package, and do so before opening a document. Keep the model plugins, styles, locales, and Facade imports, and register only one variant.
| Package | Desktop registration | Mobile registration |
|---|---|---|
@univerjs-pro/docs-table-ui | UniverDocsTableUIPlugin | UniverDocsTableMobileUIPlugin |
Facade API
Import the facade before using any of the following APIs:
import '@univerjs-pro/docs-table/facade'Insert a table
const doc = univerAPI.getActiveDocument()const table = doc?.insertTable(3, 4, { tableId: 'my-table' })table?.setCellText(0, 0, 'Name')Insert a table from data
const doc = univerAPI.getActiveDocument()doc?.insertTableFromData([ ['Name', 'Status'], ['Facade', 'Ready'],], { headerRowCount: 1 })Get all tables
const doc = univerAPI.getActiveDocument()const tables = doc?.getTables() ?? []Delete a table
const doc = univerAPI.getActiveDocument()doc?.deleteTable('my-table')Table borders
Select a table or its cells to open the contextual Table tab. The border picker provides presets for all, outer, inner, individual-edge, and no borders, along with controls for color, width, and line style. UniverDocsTableUIPlugin supplies these controls.
Editing, undo, and collaboration
Table Facade setters and structural edits are applied through document commands, so they participate in undo/redo and collaboration. setTableStyle() combines background and border changes into one history entry. setColumnType() is also undoable and synchronized, and column types follow their columns when the columns move. setCellText() replaces the whole cell value: concurrent replacements resolve as atomic values, whereas ordinary character edits use text OT. If a locked content control rejects a cell edit, the call returns false and does not consume undo/redo history.
Align the whole table
In a Traditional document, select a table and use Table → Table alignment on the Ribbon to place the table at the left, center, or right of the page content area. This setting moves the table itself and does not change text alignment inside cells. The control is disabled in Modern documents.
The value is stored in tableSource[tableId].align and supports undo/redo and saving. After the table plugin is registered, the same action is available through the public command below. Pass an existing table ID from the document snapshot. Invalid targets, disabled documents, and Modern documents return false.
import { DocsTableSetTableAlignCommand } from '@univerjs-pro/docs-table'import { TableAlignmentType } from '@univerjs/core'const aligned = await univerAPI.executeCommand(DocsTableSetTableAlignCommand.id, { unitId: documentId, tableId, value: TableAlignmentType.CENTER,})How is this guide?