API 参考

FDocumentTableCell

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

Facade object for a single docs table cell.

Access

Access through:

Example

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)cell?.setText('Owner')cell?.setBackgroundColor('#E8F1FF')

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

FDocumentTableCell.clearMarginOverride

Removes this cell's explicit margin override so it inherits from the table.

TypeScript
clearMarginOverride(): boolean

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

FDocumentTableCell.getColumnIndex

Returns the zero-based column index.

TypeScript
getColumnIndex(): number

Returns

The column index.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(2, 3)const columnIndex = cell?.getColumnIndex() // Returns 3

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

FDocumentTableCell.getContentRange

Returns the editable document range inside this cell.

TypeScript
getContentRange(): IDocsTableCellContentRange | null

Returns

The cell content range, 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)const contentRange = cell?.getContentRange() // Returns the content range of the cell

Types: IDocsTableCellContentRange

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

FDocumentTableCell.getInsertOffset

Returns the offset before this cell's final paragraph and section break.

TypeScript
getInsertOffset(): number | null

Returns

The insertion offset, 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)const insertOffset = cell?.getInsertOffset() // Returns the offset for inserting new content into the cell

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

FDocumentTableCell.getMargin

Returns the effective margin used to lay out this cell. Cell overrides take precedence over the table default and the built-in fallback.

TypeScript
getMargin(): ITableCellMargin | null

Types: ITableCellMargin

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

FDocumentTableCell.getMarginOverride

Returns this cell's explicit margin override, or null when it inherits.

TypeScript
getMarginOverride(): ITableCellMargin | null

Types: ITableCellMargin

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

FDocumentTableCell.getRowIndex

Returns the zero-based row index.

TypeScript
getRowIndex(): number

Returns

The row index.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(2, 3)const rowIndex = cell?.getRowIndex() // Returns 2

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

FDocumentTableCell.getTable

Returns the parent table facade.

TypeScript
getTable(): FDocumentTable

Returns

The parent table.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)const parentTable = cell?.getTable() // Returns the same table as `table`

Types: FDocumentTable

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

FDocumentTableCell.getText

Returns plain text in this cell.

TypeScript
getText(): string

Returns

The cell text.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)const text = cell?.getText() // Returns the text content of the cell

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

FDocumentTableCell.mergeTo

Merges this cell with a rectangular span starting from this cell.

TypeScript
mergeTo(rowSpan: number, columnSpan: number): boolean

Parameters

  • rowSpan — Required. Number of rows to include.
  • columnSpan — Required. Number of columns to include.

Returns

Whether the mutation succeeded.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)cell?.mergeTo(2, 3) // Merges a 2-row-by-3-column range starting from this cell

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

FDocumentTableCell.setBackgroundColor

Sets the cell background color.

TypeScript
setBackgroundColor(color: string): boolean

Parameters

  • color — Required. CSS color string, for example #E8F1FF.

Returns

Whether the mutation succeeded.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)cell?.setBackgroundColor('#E8F1FF') // Sets the cell background color to a light blue

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

FDocumentTableCell.setBorder

Applies border options to this cell.

TypeScript
setBorder(border: IDocsTableBorderOptions): boolean

Parameters

  • border — Required. Border preset and style options.

Returns

Whether the mutation succeeded.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')// Sets a light gray border around the cellconst cell = table.getCell(0, 0)cell?.setBorder({  preset: univerAPI.Enum.DocsTableBorderPreset.Outer,  color: '#CCCCCC',  width: 1,})

Types: IDocsTableBorderOptions

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

FDocumentTableCell.setMargin

Sets this cell's explicit margin override.

TypeScript
setMargin(margin: ITableCellMargin): boolean

Parameters

  • margin — Required.

Types: ITableCellMargin

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

FDocumentTableCell.setText

Replaces the cell text.

TypeScript
setText(text: string): boolean

Parameters

  • text — Required. The new cell text.

Returns

Whether the mutation succeeded.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)cell?.setText('Owner') // Sets the cell text to "Owner"

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

FDocumentTableCell.unmerge

Unmerges the merged range containing this cell.

TypeScript
unmerge(): boolean

Returns

Whether the mutation succeeded.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)cell?.unmerge() // Unmerges the merged range containing this cell

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

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.