API 参考

FDocumentTable

本 API 页面目前提供英文正文。代码签名与标识符不随界面语言变化。

Facade object for a single enhanced docs table.

All mutating methods execute synchronously through the Univer command service and return true when the underlying document mutation succeeds.

Access

Access through:

Example

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.describe())table?.setCellText(1, 1, 'Done')table?.setTableBorder({ color: '#3367D6', width: 1 })

Setup

Register @univerjs-pro/docs-table or a preset that includes it. In plugin mode, import @univerjs-pro/docs-table/facade. Additional methods below require their listed plugin packages. See Facade setup.

@univerjs-pro/docs-table

FDocumentTable.appendColumn

Appends a new column at the end of the table.

TypeScript
appendColumn(): boolean

Returns

true if the column was successfully appended.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.appendColumn() // Appends a new column at the end of the table

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.appendRow

Appends a new row at the end of the table.

TypeScript
appendRow(): boolean

Returns

true if the row was successfully appended.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.appendRow() // Appends a new row at the end of the table

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.deleteColumn

Deletes a single column at the specified column index.

TypeScript
deleteColumn(column: number): boolean

Parameters

  • column — Required. The zero-based column index to delete.

Returns

true if the column was successfully deleted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.deleteColumn(1) // Deletes column 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.deleteColumns

Deletes multiple columns starting from the specified column index.

TypeScript
deleteColumns(startColumn: number, count?: number): boolean

Parameters

  • startColumn — Required. The zero-based starting column index to delete.
  • count — Optional. Default: 1. The number of columns to delete.

Returns

true if the columns were successfully deleted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.deleteColumns(1, 2) // Deletes columns 1 and 2

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.deleteRow

Deletes a single row at the specified row index.

TypeScript
deleteRow(row: number): boolean

Parameters

  • row — Required. The zero-based row index to delete.

Returns

true if the row was successfully deleted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.deleteRow(1) // Deletes row 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.deleteRows

Deletes multiple rows starting from the specified row index.

TypeScript
deleteRows(startRow: number, count?: number): boolean

Parameters

  • startRow — Required. The zero-based starting row index to delete.
  • count — Optional. Default: 1. The number of rows to delete.

Returns

true if the rows were successfully deleted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.deleteRows(1, 2) // Deletes rows 1 and 2

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.deleteTable

Deletes the entire table.

TypeScript
deleteTable(): boolean

Returns

true if the table was successfully deleted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.deleteTable() // Deletes the entire table

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.describe

Returns a human-readable table summary with sample rows.

TypeScript
describe(): IDocsTableDescription

Returns

A compact description suitable for agents or logs.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.describe())

Types: IDocsTableDescription

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.distributeColumns

Distributes the width of columns evenly across a specified range of columns in the table.

TypeScript
distributeColumns(startColumn?: number, count?: number): boolean

Parameters

  • startColumn — Optional. Default: 0. The zero-based starting column index to distribute from.
  • count — Optional. Default: this.getColumnCount(). The number of columns to distribute. If not provided, it will distribute all columns starting from the startColumn to the end of the table.

Returns

true if the column widths were successfully distributed.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.distributeColumns(1, 3) // Distributes the width of columns 1 to 3 evenly

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.distributeRows

Distributes the height of rows evenly across a specified range of rows in the table.

TypeScript
distributeRows(startRow?: number, count?: number): boolean

Parameters

  • startRow — Optional. Default: 0. The zero-based starting row index to distribute from.
  • count — Optional. Default: this.getRowCount(). The number of rows to distribute. If not provided, it will distribute all rows starting from the startRow to the end of the table.

Returns

true if the row heights were successfully distributed.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.distributeRows(1, 3) // Distributes the height of rows 1 to 3 evenly

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getCell

Gets a FDocumentTableCell instance for the specified cell coordinates.

TypeScript
getCell(row: number, column: number): FDocumentTableCell | null

Parameters

  • row — Required. The zero-based row index.
  • column — Required. The zero-based column index.

Returns

The FDocumentTableCell instance, or null if the cell does not exist.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table?.getCell(0, 0)console.log(cell?.getText()) // e.g. 'Status'

Types: FDocumentTableCell

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getCellContentRange

Returns the editable document range inside a table cell. The range excludes the table cell tokens and the final section break, so block/list facades can use it as their startOffset/endOffset target.

TypeScript
getCellContentRange(row: number, column: number): IDocsTableCellContentRange | null

Parameters

  • row — Required. The zero-based row index.
  • column — Required. The zero-based column index.

Returns

The cell content range, or null if the cell does not exist.

Examples

text
const fDocument = univerAPI.getActiveDocument();const table = fDocument?.findTableByText('Status');const contentRange = table?.getCellContentRange(1, 1);console.log(contentRange); // e.g. { startOffset: 123, endOffset: 130, segmentId: 'segment-1' }

Types: IDocsTableCellContentRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getCellInsertOffset

Returns the offset before the cell's final paragraph and section break. Use this offset to insert an empty callout, quote, code block, or paragraph in the cell.

TypeScript
getCellInsertOffset(row: number, column: number): number | null

Parameters

  • row — Required. The zero-based row index.
  • column — Required. The zero-based column index.

Returns

The insertion offset, or null if the cell does not exist.

Examples

text
const fDocument = univerAPI.getActiveDocument();const table = fDocument?.findTableByText('Status');const insertOffset = table?.getCellInsertOffset(1, 1);console.log(insertOffset); // e.g. 129

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getCellMargin

Returns the effective margin used to lay out a cell. The cell override takes precedence over the table default and the built-in fallback.

TypeScript
getCellMargin(row: number, column: number): ITableCellMargin | null

Parameters

  • row — Required. The zero-based row index.
  • column — Required. The zero-based column index.

Returns

The effective margin, or null if the cell does not exist.

Types: ITableCellMargin

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getCellMarginOverride

Returns a cell's explicit margin override.

TypeScript
getCellMarginOverride(row: number, column: number): ITableCellMargin | null

Parameters

  • row — Required. The zero-based row index.
  • column — Required. The zero-based column index.

Returns

The explicit override, or null if the cell inherits its margin.

Types: ITableCellMargin

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getCellRange

Gets the table cell range for the specified cell coordinates.

TypeScript
getCellRange(row: number, column: number): IDocsTableCellRange

Parameters

  • row — Required. The zero-based row index.
  • column — Required. The zero-based column index.

Returns

The cell range, or null if the cell does not exist.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cellRange = table?.getCellRange(1, 1)console.log(cellRange) // e.g. { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 }

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getCellText

Gets the plain text content of a cell.

TypeScript
getCellText(row: number, column: number): string

Parameters

  • row — Required. The zero-based row index.
  • column — Required. The zero-based column index.

Returns

The cell text, or an empty string if the cell does not exist or has no text.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cellText = table?.getCellText(0, 0)console.log(cellText) // e.g. 'Status'

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getColumnCount

Gets the number of columns in the table.

TypeScript
getColumnCount(): number

Returns

The column count, or 0 if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getColumnCount())

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getColumnRange

Gets the cell range for the specified column index, covering all rows in the column.

TypeScript
getColumnRange(column: number): IDocsTableCellRange

Parameters

  • column — Required. The zero-based column index.

Returns

The cell range for the specified column, or null if the column does not exist.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const columnRange = table?.getColumnRange(1)console.log(columnRange) // e.g. { startRow: 0, endRow: 4, startColumn: 1, endColumn: 1 }

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getColumnsRange

Gets the cell range for the specified column index and column count, covering all rows in the columns.

TypeScript
getColumnsRange(startColumn: number, count?: number): IDocsTableCellRange

Parameters

  • startColumn — Required. The zero-based starting column index.
  • count — Optional. Default: 1. The number of columns to include in the range.

Returns

The cell range for the specified columns, or null if the starting column does not exist.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const columnsRange = table?.getColumnsRange(1, 2)console.log(columnsRange) // e.g. { startRow: 0, endRow: 4, startColumn: 1, endColumn: 2 }

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getDefaultCellMargin

Returns the effective table-level default cell margin.

TypeScript
getDefaultCellMargin(): ITableCellMargin

Types: ITableCellMargin

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getDefaultCellMarginOverride

Returns the explicit table-level default cell margin, or null when the built-in fallback is used.

TypeScript
getDefaultCellMarginOverride(): ITableCellMargin | null

Types: ITableCellMargin

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getHeaderRowCount

Gets the number of header rows in the table.

TypeScript
getHeaderRowCount(): number

Returns

The number of header rows in the table.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const headerRowCount = table?.getHeaderRowCount()

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getId

Returns the table id.

TypeScript
getId(): string

Returns

The table id stored in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getId()) // e.g. 'table-12345'

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getInfo

Returns compact table metadata for agents.

TypeScript
getInfo(): IDocsTableInfo

Returns

The id, row count, column count, metadata, and raw table source.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getInfo())

Types: IDocsTableInfo

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getMetadata

Gets the table metadata stored in the document snapshot, including header row count, title row, and column type configs.

TypeScript
getMetadata(): IDocsTableMetadata | undefined

Returns

The table metadata, or undefined if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getMetadata())

Types: IDocsTableMetadata

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getRange

Gets the table range with offsets for all cells in the table.

TypeScript
getRange(): IDocsTableOffsetRange | null

Returns

The table range with offsets, or null if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getRange())

Types: IDocsTableOffsetRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getRowCount

Gets the number of rows in the table.

TypeScript
getRowCount(): number

Returns

The row count, or 0 if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getRowCount())

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getRowHeight

Returns the row height value and its OOXML height rule.

TypeScript
getRowHeight(row: number): ITableRowSize | null

Parameters

  • row — Required.

Types: ITableRowSize

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getRowRange

Gets the cell range for the specified row index, covering all columns in the row.

TypeScript
getRowRange(row: number): IDocsTableCellRange

Parameters

  • row — Required. The zero-based row index.

Returns

The cell range for the specified row, or null if the row does not exist.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const rowRange = table?.getRowRange(1)console.log(rowRange) // e.g. { startRow: 1, endRow: 1, startColumn: 0, endColumn: 4 }

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getRowsRange

Gets the cell range for the specified row index and row count, covering all columns in the rows.

TypeScript
getRowsRange(startRow: number, count?: number): IDocsTableCellRange

Parameters

  • startRow — Required. The zero-based starting row index.
  • count — Optional. Default: 1. The number of rows to include in the range.

Returns

The cell range for the specified rows, or null if the starting row does not exist.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const rowsRange = table?.getRowsRange(1, 2)console.log(rowsRange) // e.g. { startRow: 1, endRow: 2, startColumn: 0, endColumn: 4 }

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getSegmentId

Get the segment id of this table. The main body tables have an empty string segment id. The header and footer tables have a non-empty string segment id.

TypeScript
getSegmentId(): string

Returns

The segment id.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getSegmentId())

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getSource

Gets the raw table source from the document snapshot, including all table rows, cells, and columns.

TypeScript
getSource(): ITable | undefined

Returns

The table source, or undefined if the table is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getSource())

Types: ITable

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.getTableRange

Gets the table cell range covering all cells in the table.

TypeScript
getTableRange(): IDocsTableCellRange

Returns

The table cell range covering all cells in the table, or null if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')console.log(table?.getTableRange())

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.hasTitleRow

Checks if the table has a title row.

TypeScript
hasTitleRow(): boolean

Returns

true if the table has a title row, otherwise false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const hasTitle = table?.hasTitleRow()

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertColumnAfter

Inserts a new column after the specified column index.

TypeScript
insertColumnAfter(column: number): boolean

Parameters

  • column — Required. The zero-based column index to insert after.

Returns

true if the column was successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertColumnAfter(1) // Inserts a new column after column 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertColumnBefore

Inserts a new column before the specified column index.

TypeScript
insertColumnBefore(column: number): boolean

Parameters

  • column — Required. The zero-based column index to insert before.

Returns

true if the column was successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertColumnBefore(1) // Inserts a new column before column 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertColumnsAfter

Inserts multiple columns after the specified column index.

TypeScript
insertColumnsAfter(column: number, count: number): boolean

Parameters

  • column — Required. The zero-based column index to insert after.
  • count — Required. The number of columns to insert.

Returns

true if the columns were successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertColumnsAfter(1, 2) // Inserts 2 new columns after column 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertColumnsBefore

Inserts multiple columns before the specified column index.

TypeScript
insertColumnsBefore(column: number, count: number): boolean

Parameters

  • column — Required. The zero-based column index to insert before.
  • count — Required. The number of columns to insert.

Returns

true if the columns were successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertColumnsBefore(1, 2) // Inserts 2 new columns before column 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertRowAfter

Inserts a new row after the specified row index.

TypeScript
insertRowAfter(row: number): boolean

Parameters

  • row — Required. The zero-based row index to insert after.

Returns

true if the row was successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertRowAfter(1) // Inserts a new row after row 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertRowBefore

Inserts a new row before the specified row index.

TypeScript
insertRowBefore(row: number): boolean

Parameters

  • row — Required. The zero-based row index to insert before.

Returns

true if the row was successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertRowBefore(1) // Inserts a new row before row 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertRowsAfter

Inserts multiple rows after the specified row index.

TypeScript
insertRowsAfter(row: number, count: number): boolean

Parameters

  • row — Required. The zero-based row index to insert after.
  • count — Required. The number of rows to insert.

Returns

true if the rows were successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertRowsAfter(1, 2) // Inserts 2 new rows after row 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertRowsBefore

Inserts multiple rows before the specified row index.

TypeScript
insertRowsBefore(row: number, count: number): boolean

Parameters

  • row — Required. The zero-based row index to insert before.
  • count — Required. The number of rows to insert.

Returns

true if the rows were successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertRowsBefore(1, 2) // Inserts 2 new rows before row 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.insertTitleRow

Inserts a title row at the top of the table.

TypeScript
insertTitleRow(): boolean

Returns

true if the title row was successfully inserted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.insertTitleRow() // Inserts a title row at the top of the table

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.mergeCells

Merges a range of cells in the table into a single cell. The content of the merged cell will be taken from the top-left cell in the range.

TypeScript
mergeCells(range: IDocsTableCellRange): boolean

Parameters

  • range — Required. The range of cells to merge.

Returns

true if the cells were successfully merged.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Merges the cells in the range from row 1 to 2 and column 1 to 2 into a single celltable?.mergeCells({  startRow: 1,  endRow: 2,  startColumn: 1,  endColumn: 2,})

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.moveColumn

Moves a single column to a target column index with the specified insert position relative to the target column.

TypeScript
moveColumn(column: number, targetColumn: number, position?: DocsTableColumnInsertPosition): boolean

Parameters

  • column — Required. The zero-based column index to move.
  • targetColumn — Required. The zero-based target column index to move to.
  • position — Optional. Default: DocsTableInsertPosition.Left. The position to insert the moved column relative to the target column. Defaults to Left.

Returns

true if the column was successfully moved.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.moveColumn(1, 3, univerAPI.Enum.DocsTableColumnInsertPosition.Right) // Moves column 1 to right of column 3

Types: DocsTableColumnInsertPosition

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.moveColumns

Moves multiple columns to a target column index with the specified insert position relative to the target column.

TypeScript
moveColumns(startColumn: number, count: number, targetColumn: number, position?: DocsTableColumnInsertPosition): boolean

Parameters

  • startColumn — Required. The zero-based starting column index to move.
  • count — Required. The number of columns to move.
  • targetColumn — Required. The zero-based target column index to move to.
  • position — Optional. Default: DocsTableInsertPosition.Left. The position to insert the moved columns relative to the target column. Defaults to Left.

Returns

true if the columns were successfully moved.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.moveColumns(1, 2, 4, univerAPI.Enum.DocsTableColumnInsertPosition.Right) // Moves columns 1 and 2 to right of column 4

Types: DocsTableColumnInsertPosition

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.moveRow

Moves a single row to a target row index with the specified insert position relative to the target row.

TypeScript
moveRow(row: number, targetRow: number, position?: DocsTableRowInsertPosition): boolean

Parameters

  • row — Required. The zero-based row index to move.
  • targetRow — Required. The zero-based target row index to move to.
  • position — Optional. Default: DocsTableInsertPosition.Above. The position to insert the moved row relative to the target row. Defaults to Above.

Returns

true if the row was successfully moved.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.moveRow(1, 3, univerAPI.Enum.DocsTableRowInsertPosition.Below) // Moves row 1 to below row 3

Types: DocsTableRowInsertPosition

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.moveRows

Moves multiple rows to a target row index with the specified insert position relative to the target row.

TypeScript
moveRows(startRow: number, count: number, targetRow: number, position?: DocsTableRowInsertPosition): boolean

Parameters

  • startRow — Required. The zero-based starting row index to move.
  • count — Required. The number of rows to move.
  • targetRow — Required. The zero-based target row index to move to.
  • position — Optional. Default: DocsTableInsertPosition.Above. The position to insert the moved rows relative to the target row. Defaults to Above.

Returns

true if the rows were successfully moved.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.moveRows(1, 2, 4, univerAPI.Enum.DocsTableRowInsertPosition.Below) // Moves rows 1 and 2 to below row 4

Types: DocsTableRowInsertPosition

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.moveTableBy

Moves the entire table by the specified horizontal and vertical offsets.

TypeScript
moveTableBy(deltaX: number, deltaY: number): boolean

Parameters

  • deltaX — Required. Horizontal offset delta applied to the table's floating position
  • deltaY — Required. Vertical offset delta applied to the table's floating position

Returns

true if the table was successfully moved.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.moveTableBy(50, 100) // Moves the table 50 units to the right and 100 units down

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.moveTableToOffset

Moves the entire table to the specified offset in the document's data stream.

TypeScript
moveTableToOffset(offset: number): boolean

Parameters

  • offset — Required. The target offset to move the table to.

Returns

true if the table was successfully moved.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.moveTableToOffset(500) // Moves the table to offset 500 in the document's data stream

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.pinHeaderRows

Pins the specified number of rows at the top of the table as header rows, which will be repeated on each page when the table spans multiple pages.

TypeScript
pinHeaderRows(count: number): boolean

Parameters

  • count — Required. The number of rows to pin as header rows.

Returns

true if the header rows were successfully pinned.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.pinHeaderRows(2) // Pins the first 2 rows of the table as header rows

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.selectCell

Selects a single cell in the table.

TypeScript
selectCell(row: number, column: number): boolean

Parameters

  • row — Required. The zero-based row index of the cell to select.
  • column — Required. The zero-based column index of the cell to select.

Returns

true if the selection was successfully set, or false if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.selectCell(1, 1) // Selects the cell at row 1, column 1

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.selectColumn

Selects a single column in the table.

TypeScript
selectColumn(column: number): boolean

Parameters

  • column — Required. The zero-based column index to select.

Returns

true if the selection was successfully set, or false if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.selectColumn(1)

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.selectColumns

Selects multiple columns in the table.

TypeScript
selectColumns(startColumn: number, count?: number): boolean

Parameters

  • startColumn — Required. The zero-based starting column index to select.
  • count — Optional. Default: 1. The number of columns to select.

Returns

true if the selection was successfully set, or false if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.selectColumns(1, 2) // Selects columns 1 and 2

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.selectRange

Selects a range of cells in the table with the specified selection kind.

TypeScript
selectRange(range: IDocsTableCellRange, kind?: Exclude<DocsTableSelectionKind, DocsTableSelectionKind.None | DocsTableSelectionKind.Text>): boolean

Parameters

  • range — Required. The cell range to select.
  • kind — Optional. Default: DocsTableSelectionKind.Range. The selection kind, which determines the selection behavior and UI. Defaults to Range.

Returns

true if the selection was successfully set, or false if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Select a range of cells from row 1 to 2 and column 1 to 2 with the 'Range' selection kindtable.selectRange({  startRow: 1,  endRow: 2,  startColumn: 1,  endColumn: 2,})

Types: IDocsTableCellRange · Exclude · DocsTableSelectionKind · DocsTableSelectionKind.None · DocsTableSelectionKind.Text

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.selectRow

Selects a single row in the table.

TypeScript
selectRow(row: number): boolean

Parameters

  • row — Required. The zero-based row index to select.

Returns

true if the selection was successfully set, or false if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.selectRow(1)

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.selectRows

Selects multiple rows in the table.

TypeScript
selectRows(startRow: number, count?: number): boolean

Parameters

  • startRow — Required. The zero-based starting row index to select.
  • count — Optional. Default: 1. The number of rows to select.

Returns

true if the selection was successfully set, or false if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.selectRows(1, 2) // Selects rows 1 and 2

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.selectTable

Selects the entire table.

TypeScript
selectTable(): boolean

Returns

true if the selection was successfully set, or false if the table source is not found in the document snapshot.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.selectTable()

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setBorder

Sets the border properties for a range of cells in the table.

TypeScript
setBorder(range: IDocsTableCellRange, options: IDocsTableBorderOptions): boolean

Parameters

  • range — Required. The range of cells to set the border for.
  • options — Required. The border options, including color, width, dash style, and presets for which sides to apply the border to.

Returns

true if the cell border was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Sets a solid red border with a width of 2 for the cells in the range from row 1 to 2 and column 1 to 2table?.setBorder(  {    startRow: 1,    endRow: 2,    startColumn: 1,    endColumn: 2,  },  {    preset: univerAPI.Enum.DocsTableBorderPreset.All,    color: '#ff0000',    width: 2,  },)// Sets a dashed blue border with a width of 1 for the cells in the range from row 0 to 0 and column 0 to 2, applying only to the bottom sidetable?.setBorder(  {    startRow: 0,    endRow: 0,    startColumn: 0,    endColumn: 2,  },  {    preset: univerAPI.Enum.DocsTableBorderPreset.Bottom,    border: {      color: { rgb: '#0000ff' },      width: { v: 1 },      dashStyle: univerAPI.Enum.DashStyleType.DASHED,    },  },)

Types: IDocsTableCellRange · IDocsTableBorderOptions

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setCellBackground

Sets the background color of a range of cells in the table.

TypeScript
setCellBackground(range: IDocsTableCellRange, color: string): boolean

Parameters

  • range — Required. The range of cells to set the background color for.
  • color — Required. The background color to set, specified as a hex string (e.g., #ff0000 for red).

Returns

true if the cell background color was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Sets the background color of the cells in the range from row 1 to 2 and column 1 to 2 to redtable?.setCellBackground(  {    startRow: 1,    endRow: 2,    startColumn: 1,    endColumn: 2,  },  '#ff0000',)

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setCellMargin

Sets or clears the explicit margin override for a range of cells. Pass null to make the cells inherit the table default.

TypeScript
setCellMargin(range: IDocsTableCellRange, margin: Nullable<ITableCellMargin>): boolean

Parameters

  • range — Required. The target cell range.
  • margin — Required. The margin override, or null to clear it.

Returns

Whether the mutation succeeded.

Types: IDocsTableCellRange · Nullable · ITableCellMargin

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setCellText

Sets the text content of a specific cell in the table. If the cell is merged, the text will be set for the entire merged cell range.

TypeScript
setCellText(row: number, column: number, text: string): boolean

Parameters

  • row — Required. The zero-based row index of the cell to set text for.
  • column — Required. The zero-based column index of the cell to set text for.
  • text — Required. The text content to set in the cell.

Returns

true if the cell text was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.setCellText(1, 1, 'In Progress') // Sets the text of the cell at row 1, column 1 to 'In Progress'

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setColumnType

Sets the metadata type of a specific column in the table.

The column type is used as the value parsing hint for table features such as sorting. It does not enable dedicated cell editors or rendering for date, checkbox, or dropdown columns.

TypeScript
setColumnType(column: number, config: IDocsTableColumnTypeConfig): boolean

Parameters

  • column — Required. The zero-based column index to set the type for.
  • config — Required. The column type configuration, including the type and any additional options specific to the column type.

Returns

true if the column type metadata was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Sorts column 2 as date values when table sorting is applied.table?.setColumnType(2, {  type: univerAPI.Enum.DocsTableColumnType.Date,})

Types: IDocsTableColumnTypeConfig

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setColumnWidth

Sets the width of a specific column in the table.

TypeScript
setColumnWidth(column: number, width: number): boolean

Parameters

  • column — Required. The zero-based column index to set the width for.
  • width — Required. The width value to set for the column.

Returns

true if the column width was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.setColumnWidth(1, 100) // Sets the width of column 1 to 100 units

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setDefaultCellMargin

Sets or clears the table-level default cell margin. Pass null to restore the built-in fallback.

TypeScript
setDefaultCellMargin(margin: Nullable<ITableCellMargin>): boolean

Parameters

  • margin — Required. The table default, or null to clear it.

Returns

Whether the mutation succeeded.

Types: Nullable · ITableCellMargin

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setHeaderRowCount

Sets the number of header rows in the table. Header rows are typically styled differently and repeated on each page when the table spans multiple pages.

TypeScript
setHeaderRowCount(count: number): boolean

Parameters

  • count — Required. The number of header rows to set for the table.

Returns

true if the header row count was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.setHeaderRowCount(2) // Sets the first 2 rows of the table as header rows

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setRowHeight

Sets the height of a specific row in the table.

TypeScript
setRowHeight(row: number, height: number, hRule?: TableRowHeightRule): boolean

Parameters

  • row — Required. The zero-based row index to set the height for.
  • height — Required. The height value to set for the row.
  • hRule — Optional. Default: TableRowHeightRule.AT_LEAST.

Returns

true if the row height was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.setRowHeight(1, 30) // Sets the height of row 1 to 30 units

Types: TableRowHeightRule

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setTableBackground

Sets the background color for the entire table.

TypeScript
setTableBackground(color: string): boolean

Parameters

  • color — Required. The background color to set for the table, specified as a hex string (e.g., #ff0000 for red).

Returns

true if the table background color was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.setTableBackground('#ff0000') // Sets the background color of the entire table to red

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setTableBorder

Sets the border properties for the entire table.

TypeScript
setTableBorder(border: IDocsTableBorderOptions): boolean

Parameters

  • border — Required. The border options, including color, width, dash style, and presets for which sides to apply the border to.

Returns

true if the table border was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Sets a solid red border with a width of 2 for the entire tabletable?.setTableBorder({  preset: univerAPI.Enum.DocsTableBorderPreset.All,  color: '#ff0000',  width: 2,})// Sets a dashed blue border with a width of 1 for the entire table, applying only to the bottom sidetable?.setTableBorder({  preset: univerAPI.Enum.DocsTableBorderPreset.Bottom,  border: {    color: { rgb: '#0000ff' },    width: { v: 1 },    dashStyle: univerAPI.Enum.DashStyleType.DASHED,  },})

Types: IDocsTableBorderOptions

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.setTableStyle

Sets the overall style for the entire table, including background color and border properties.

TypeScript
setTableStyle(style: IDocsTableStyle): boolean

Parameters

  • style — Required. The table style options, including background color and border properties.

Returns

true if the table style was successfully set.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Sets the background color of the entire table to light gray and applies a solid black border with a width of 1table?.setTableStyle({  backgroundColor: '#f0f0f0',  border: {    preset: univerAPI.Enum.DocsTableBorderPreset.All,    color: '#000000',    width: 1,  },})

Types: IDocsTableStyle

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.sortByColumn

Sort the table by a specific column in either ascending or descending order.

TypeScript
sortByColumn(column: number, direction: DocsTableSortDirection): boolean

Parameters

  • column — Required. The zero-based column index to sort by.
  • direction — Required. The direction to sort the column, either ascending or descending.

Returns

true if the table was successfully sorted.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')table?.sortByColumn(1, univerAPI.Enum.DocsTableSortDirection.Asc) // Sorts the table by column 1 in ascending order

Types: DocsTableSortDirection

Package: @univerjs-pro/docs-table · Type definitions

FDocumentTable.unmergeCells

Unmerges a previously merged cell back into individual cells based on the specified range.

TypeScript
unmergeCells(range: IDocsTableCellRange): boolean

Parameters

  • range — Required. The range of the merged cell to unmerge, which should match the original merge range.

Returns

true if the cells were successfully unmerged.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Unmerges the previously merged cell in the range from row 1 to 2 and column 1 to 2 back into individual cellstable?.unmergeCells({  startRow: 1,  endRow: 2,  startColumn: 1,  endColumn: 2,})

Types: IDocsTableCellRange

Package: @univerjs-pro/docs-table · Type definitions

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.