# Workbook.BatchAsync Method

> Workbook.BatchAsync method in the TX Sheet Control .NET API: Collects synchronous workbook operations and applies them as one atomic undoable transaction.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Method
- **Namespace:** `TXTextControl.TXSheetControl.Server`
- **Package:** `TXTextControl.TXSheetControl.Server` (assembly `TXTextControl.TXSheetControl.Api.dll`, from the private NuGet feed or the supplied NuGet folder)
- **Package:** `TXTextControl.TXSheetControl.Blazor` (assembly `TXTextControl.TXSheetControl.Api.dll`, from the private NuGet feed or the supplied NuGet folder)
- **Path:** TX Sheet Control > API Reference > .NET API > TXTextControl.TXSheetControl.Server > Workbook > Workbook.BatchAsync Method
- **1128 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/batchasync-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/batchasync-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/batchasync-method/llms-full.txt

---

Collects synchronous workbook operations and applies them as one atomic undoable transaction.

### Syntax

#### Overload 1

```csharp
public Task BatchAsync(Action<WorkbookBatch> collect, CancellationToken cancellationToken = default)
```

| Parameter | Type | Optional | Description |
|---|---|---|---|
| `collect` | `Action<WorkbookBatch>` | No | Synchronous callback that adds worksheet-bound operations to a batch. |
| `cancellationToken` | `CancellationToken` | Yes | Cancels the pending operation. |

Return value: `Task`. The operation result, returned asynchronously.

#### Overload 2

```csharp
public Task<JsonElement> BatchAsync(IReadOnlyList<WorkbookCommand> commands, CancellationToken cancellationToken = default)
```

| Parameter | Type | Optional | Description |
|---|---|---|---|
| `commands` | `IReadOnlyList<WorkbookCommand>` | No | Operation-specific input; see this type's units and ownership contract. |
| `cancellationToken` | `CancellationToken` | Yes | Cancels the pending operation. |

Return value: `Task<JsonElement>`. The operation result, returned asynchronously.

### Examples

Set the heading, data, total formula and currency formatting in one atomic transaction, then export the invoice.

```csharp
using TXTextControl.TXSheetControl.Server;

async Task<byte[]> CreateInvoiceInOneTransactionAsync(ServerSheetControl control)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    var title = sheet.Cell("A1");
    await book.BatchAsync(batch =>
    {
        batch.SetText(title, "October invoice");
        batch.Format(title, new { fontFamily = "Liberation Sans", fontSize = 16, bold = true, textColor = "#ffffff", fillColor = "#163b63" });
        batch.SetValues(sheet.Range("B8:B9"), [[120], [80]]);
        batch.SetFormula(sheet.Cell("B10"), "=SUM(B8:B9)");
        batch.Format(sheet.Range("B8:B10"), new { numberFormatCode = "#,##0.00", fontFamily = "Liberation Sans", fontSize = 11 });
    });

    return await control.SaveAsync(StreamType.PDF);
}
```

### Remarks

Use the member with an instance or settings object from the documented package. Await task-returning operations. Document-bound handles must be resolved again after loading or deleting their owner.

### See Also

- [Workbook Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/llms-full.txt)
- [Workbooks and Worksheets](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/workbooks/llms-full.txt)
- [WorkbookBatch Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbookbatch/llms-full.txt)
- [WorkbookCommand Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbookcommand/llms-full.txt)

---

## Nearby

- **Previous:** [Workbook.ApplyCellStyleAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/applycellstyleasync-method/llms-full.txt)
- **Next:** [Workbook.Calculation Property](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/calculation-property/llms-full.txt)
