# PivotTableCollection Class

> PivotTableCollection class in the TX Sheet Control .NET API: Workbook-wide or destination-worksheet-scoped PivotTable collection. All mutations are undoable.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Class
- **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)
- **Inherits:** `TXTextControl.TXSheetControl.Server.DocumentObject`
- **Path:** TX Sheet Control > API Reference > .NET API > TXTextControl.TXSheetControl.Server > PivotTableCollection Class
- **1065 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/llms-full.txt

---

Workbook-wide or destination-worksheet-scoped PivotTable collection. All mutations are undoable.

Pivot handles are obtained through the owning workbook or worksheet collection.

### Members

| Member | Description |
|---|---|
| [GetCountAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/getcountasync-method/llms-full.txt) | Returns the number of pivots in the collection. |
| [ListAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/listasync-method/llms-full.txt) | Returns detached pivot definitions in workbook order. |
| [AtAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/atasync-method/llms-full.txt) | Resolves a zero-based index. An out-of-range index fails. |
| [GetAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/getasync-method/llms-full.txt) | Resolves a unique name or stable identity. An absent pivot fails. |
| [AddAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/addasync-method/llms-full.txt) | Creates and materializes a pivot atomically. Overlap, protection and invalid source fields fail without changing the workbook. |
| [RemoveAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/removeasync-method/llms-full.txt) | Removes a pivot; keepValues retains its output as ordinary static cells. |
| [RefreshAllAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/refreshallasync-method/llms-full.txt) | Refreshes all pivots in this collection in one transaction. |

### Example

```csharp
using TXTextControl.TXSheetControl.Server;

await using var control = new ServerSheetControl();
var workbook = control.Workbook;
var source = await workbook.Sheets.AtAsync(0);
await source.Range("A1:D5").SetValuesAsync([
    ["Region", "Category", "Revenue", "Cost"],
    ["Europe", "Software", 1250, 500], ["Europe", "Services", 700, 350],
    ["Americas", "Software", 1800, 900], ["Americas", "Services", 950, 400]
]);
var report = await workbook.Sheets.AddAsync("Sales Pivot");
var pivot = await report.PivotTables.AddAsync(new PivotTableOptions {
    Name = "RegionalSales", Source = new() { SheetId = source.Id, Range = "A1:D5" },
    Destination = new() { SheetId = report.Id, Cell = "B3" },
    Rows = [new() { Field = "Region" }], Columns = [new() { Field = "Category" }],
    Values = [new() { Field = "Revenue", Caption = "Sales", NumberFormatCode = "$#,##0.00" }]
});
```

See [Pivot Tables](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/pivot-tables/llms-full.txt) for field settings, output and lifetime rules.

---

## In This Section

- [PivotTableCollection.AddAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/addasync-method/llms-full.txt): PivotTableCollection.AddAsync method in the .NET API: Creates and materializes a pivot atomically; overlap, protection or invalid fields fail without changes.
- [PivotTableCollection.AtAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/atasync-method/llms-full.txt): PivotTableCollection.AtAsync method in the TX Sheet Control .NET API: Resolves a zero-based index. An out-of-range index fails.
- [PivotTableCollection.GetAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/getasync-method/llms-full.txt): PivotTableCollection.GetAsync method in the TX Sheet Control .NET API: Resolves a unique name or stable identity. An absent pivot fails.
- [PivotTableCollection.GetCountAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/getcountasync-method/llms-full.txt): PivotTableCollection.GetCountAsync method in the TX Sheet Control .NET API: Returns the number of pivots in the collection.
- [PivotTableCollection.ListAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/listasync-method/llms-full.txt): PivotTableCollection.ListAsync method in the TX Sheet Control .NET API: Returns detached pivot definitions in workbook order.
- [PivotTableCollection.RefreshAllAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/refreshallasync-method/llms-full.txt): PivotTableCollection.RefreshAllAsync method in the TX Sheet Control .NET API: Refreshes all pivots in this collection in one transaction.
- [PivotTableCollection.RemoveAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/removeasync-method/llms-full.txt): PivotTableCollection.RemoveAsync method in the TX Sheet Control .NET API: Removes a pivot; keepValues retains its output as ordinary static cells.

---

## Nearby

- **Previous:** [PivotTable.RemoveAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottable/removeasync-method/llms-full.txt)
- **Next:** [PivotTableCollection.GetCountAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pivottablecollection/getcountasync-method/llms-full.txt)
