# Javascript: TableCell.setFormula Method

> Sets the table cell's formula. For each table cell a formula can be defined which is used to calculate the cell's text. The formula can contain references to other table cells in the same table. When the text of a referenced cell changes, the cell which references it is automatically updated.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: TableCell.setFormula Method
- **449 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tablecell/setformula-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tablecell/setformula-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tablecell/setformula-method/llms-full.txt

---

### Description

Sets the table cell's formula. For each table cell a formula can be defined which is used to calculate the cell's text. The formula can contain references to other table cells in the same table. When the text of a referenced cell changes, the cell which references it is automatically updated.

### Syntax

```javascript
<void> TableCell.setFormula(<string> formula, [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| formula | The cell's formula. |
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `TableCell.setFormula` in a practical document-editing workflow. It sets the table cell's formula. For each table cell a formula can be defined which is used to calculate the cell's text. The formula can contain references to other table cells in the same table. When the text of a referenced cell changes, the cell which references it is automatically updated.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

function configureFormula(tableCell) {
    tableCell.setFormula(
        "Quarterly report",
        function() {
            console.log("set formula completed.");
        },
        onTxError
    );
}
```

---

## Nearby

- **Previous:** [Javascript: TableCell.select Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tablecell/select-method/llms-full.txt)
- **Next:** [Javascript: TableCell.setName Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tablecell/setname-method/llms-full.txt)
