Table
Register table support
Slides table support consists of two packages, one for the model and one for the UI:
import { UniverSlidesTablePlugin } from '@univerjs-pro/slides-table'import { UniverSlidesTableUIPlugin } from '@univerjs-pro/slides-table-ui'import SlidesTableUIEnUS from '@univerjs-pro/slides-table-ui/locale/en-US'import '@univerjs-pro/slides-table-ui/lib/index.css'import '@univerjs-pro/slides-table/facade'univer.registerPlugin(UniverSlidesTablePlugin)univer.registerPlugin(UniverSlidesTableUIPlugin)Mobile support
Configure the mobile editor first. In the plugin-mode setup on this page, replace the desktop registrations below with the mobile exports from the same packages, 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/slides-table-ui | UniverSlidesTableUIPlugin | UniverSlidesTableMobileUIPlugin |
Package responsibilities
@univerjs-pro/slides-tablestores table elements in the slide model and provides the facade APIs for table operations.@univerjs-pro/slides-table-uiprovides the browser editing UI, including render integration, selection behavior, and context menu actions. The package also provides@univerjs-pro/slides-table-ui/locale/*and@univerjs-pro/slides-table-ui/lib/index.css.
Runtime choices
A browser editor requires both packages. In a Node.js process, import only the model package unless browser rendering is also required.
univer.registerPlugin(UniverSlidesPlugin)univer.registerPlugin(UniverSlidesTablePlugin)Register table support before opening or importing a deck that may contain table elements. Otherwise the runtime cannot fully interpret those elements.
Stable table colors
When a table is inserted or its style changes, the plugin resolves the current theme palette into a snapshot that the table owns. Existing tables keep those colors after the global Univer theme changes, and selecting another table style creates a new snapshot. Standard Facade operations handle this automatically.
Facade API
Import the facade entry to add table methods to FSlide:
import '@univerjs-pro/slides-table/facade'Create a table from plain text data:
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideById('slide-1')const table = fSlide.insertTableFromData( [ ['Quarter', 'Owner', 'Status'], ['Q1', 'Sales', 'Done'], ['Q2', 'Marketing', 'In progress'], ], { id: 'status-table', rowHeight: 42, columnWidth: 160, },)Use the table builder when explicit control over position and size is required:
const tableInfo = fSlide.newTable() .setValues([ ['Metric', 'Value'], ['Revenue', '$120K'], ]) .setRows(2) .setColumns(2) .setAbsolutePosition(80, 120) .setSize(420, 180) .build()const table = fSlide.insertTable(tableInfo)Read and update table cells:
const table = fSlide.getTableById('status-table') ?? fSlide.getTableAt(0)if (table) { console.log(table.describe()) console.log(table.getCellText(0, 0)) table.getCell(1, 2)?.setText('Blocked') table.getCell(0, 0)?.setBackgroundColor('#E8F1FF')}Update or remove an existing table:
const table = fSlide.getTableById('status-table')if (table) { const nextTableInfo = table.toBuilder() .setValues([ ['Quarter', 'Owner', 'Status'], ['Q1', 'Sales', 'Done'], ['Q2', 'Marketing', 'Blocked'], ]) .setSize(480, 200) .build() fSlide.updateTable(nextTableInfo) fSlide.removeTable(table)}Table row and column indexes are zero-based. The builder grows its row and column counts to fit the values passed to it, so for a simple table, setValues() can serve as the source of truth.
How is this guide?