# FDocumentTableCell

> Language fallback: requested `zh-CN`; content is `en-US`.

- Human documentation: [https://docs.univer.ai/zh-CN/reference/facade/document-table-cell](https://docs.univer.ai/zh-CN/reference/facade/document-table-cell)

- Agent Markdown: [https://docs.univer.ai/zh-CN/reference/facade/document-table-cell.md](https://docs.univer.ai/zh-CN/reference/facade/document-table-cell.md)

- Requested language: `zh-CN`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/document-table-cell.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/document-table-cell.mdx)

---

Facade object for a single docs table cell.

## Access

Access through:

* [`FDocumentTable.getCell()`](https://docs.univer.ai/zh-CN/reference/facade/document-table.md#getcell)

## Example

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) 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](https://docs.univer.ai/zh-CN/guides/docs/getting-started/facade.md).

## `@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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.getColumnIndex`

Returns the zero-based column index.

```typescript
getColumnIndex(): number
```

**Returns**

The column index.

**Examples**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `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**

```ts
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`](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/types.d.ts)

**Package:** [`@univerjs-pro/docs-table`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `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**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `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`](https://unpkg.com/@univerjs/core@1.0.0-rc.0/lib/types/types/interfaces/i-document-data.d.ts)

**Package:** [`@univerjs-pro/docs-table`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.getMarginOverride`

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

```typescript
getMarginOverride(): ITableCellMargin | null
```

**Types:** [`ITableCellMargin`](https://unpkg.com/@univerjs/core@1.0.0-rc.0/lib/types/types/interfaces/i-document-data.d.ts)

**Package:** [`@univerjs-pro/docs-table`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.getRowIndex`

Returns the zero-based row index.

```typescript
getRowIndex(): number
```

**Returns**

The row index.

**Examples**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.getTable`

Returns the parent table facade.

```typescript
getTable(): FDocumentTable
```

**Returns**

The parent table.

**Examples**

```ts
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`](https://docs.univer.ai/zh-CN/reference/facade/document-table.md)

**Package:** [`@univerjs-pro/docs-table`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.getText`

Returns plain text in this cell.

```typescript
getText(): string
```

**Returns**

The cell text.

**Examples**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `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**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `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**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `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**

```ts
const fDocument = univerAPI.getActiveDocument()
const table = fDocument?.findTableByText('Status')

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

**Types:** [`IDocsTableBorderOptions`](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/types.d.ts)

**Package:** [`@univerjs-pro/docs-table`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.setMargin`

Sets this cell's explicit margin override.

```typescript
setMargin(margin: ITableCellMargin): boolean
```

**Parameters**

* `margin` — Required.

**Types:** [`ITableCellMargin`](https://unpkg.com/@univerjs/core@1.0.0-rc.0/lib/types/types/interfaces/i-document-data.d.ts)

**Package:** [`@univerjs-pro/docs-table`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.setText`

Replaces the cell text.

```typescript
setText(text: string): boolean
```

**Parameters**

* `text` — Required. The new cell text.

**Returns**

Whether the mutation succeeded.

**Examples**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)

### `FDocumentTableCell.unmerge`

Unmerges the merged range containing this cell.

```typescript
unmerge(): boolean
```

**Returns**

Whether the mutation succeeded.

**Examples**

```ts
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`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-table.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-table@1.0.0-rc.0/lib/types/facade/f-document-table-cell.d.ts)
