FDocumentTableCell
Facade object for a single docs table cell.
Access
Access through:
Example
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.
clearMarginOverride(): booleanPackage: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.getColumnIndex
Returns the zero-based column index.
getColumnIndex(): numberReturns
The column index.
Examples
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(2, 3)const columnIndex = cell?.getColumnIndex() // Returns 3Package: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.getContentRange
Returns the editable document range inside this cell.
getContentRange(): IDocsTableCellContentRange | nullReturns
The cell content range, or null if the cell does not exist.
Examples
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 cellTypes: IDocsTableCellContentRange
Package: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.getInsertOffset
Returns the offset before this cell's final paragraph and section break.
getInsertOffset(): number | nullReturns
The insertion offset, or null if the cell does not exist.
Examples
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 cellPackage: @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.
getMargin(): ITableCellMargin | nullTypes: ITableCellMargin
Package: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.getMarginOverride
Returns this cell's explicit margin override, or null when it inherits.
getMarginOverride(): ITableCellMargin | nullTypes: ITableCellMargin
Package: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.getRowIndex
Returns the zero-based row index.
getRowIndex(): numberReturns
The row index.
Examples
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(2, 3)const rowIndex = cell?.getRowIndex() // Returns 2Package: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.getTable
Returns the parent table facade.
getTable(): FDocumentTableReturns
The parent table.
Examples
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.
getText(): stringReturns
The cell text.
Examples
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 cellPackage: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.mergeTo
Merges this cell with a rectangular span starting from this cell.
mergeTo(rowSpan: number, columnSpan: number): booleanParameters
rowSpan— Required. Number of rows to include.columnSpan— Required. Number of columns to include.
Returns
Whether the mutation succeeded.
Examples
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 cellPackage: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.setBackgroundColor
Sets the cell background color.
setBackgroundColor(color: string): booleanParameters
color— Required. CSS color string, for example#E8F1FF.
Returns
Whether the mutation succeeded.
Examples
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 bluePackage: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.setBorder
Applies border options to this cell.
setBorder(border: IDocsTableBorderOptions): booleanParameters
border— Required. Border preset and style options.
Returns
Whether the mutation succeeded.
Examples
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.
setMargin(margin: ITableCellMargin): booleanParameters
margin— Required.
Types: ITableCellMargin
Package: @univerjs-pro/docs-table · Type definitions
FDocumentTableCell.setText
Replaces the cell text.
setText(text: string): booleanParameters
text— Required. The new cell text.
Returns
Whether the mutation succeeded.
Examples
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.
unmerge(): booleanReturns
Whether the mutation succeeded.
Examples
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.findTableByText('Status')const cell = table.getCell(0, 0)cell?.unmerge() // Unmerges the merged range containing this cellPackage: @univerjs-pro/docs-table · Type definitions
How is this guide?