TX Sheet Control

PivotTableCollection Class

Class
Namespace
TXTextControl.TXSheetControl.Server
Package
TXTextControl.TXSheetControl.Server from the private NuGet feed or the supplied NuGet folder
Assembly
TXTextControl.TXSheetControl.Api.dll
Install
dotnet add package TXTextControl.TXSheetControl.Server .NET 10 and later.
Also in
TXTextControl.TXSheetControl.Blazor as TXTextControl.TXSheetControl.Api.dll
Inherits
  1. DocumentObject
  2. PivotTableCollection

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

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

Members

MemberDescription
GetCountAsyncReturns the number of pivots in the collection.
ListAsyncReturns detached pivot definitions in workbook order.
AtAsyncResolves a zero-based index. An out-of-range index fails.
GetAsyncResolves a unique name or stable identity. An absent pivot fails.
AddAsyncCreates and materializes a pivot atomically. Overlap, protection and invalid source fields fail without changing the workbook.
RemoveAsyncRemoves a pivot; keepValues retains its output as ordinary static cells.
RefreshAllAsyncRefreshes all pivots in this collection in one transaction.

Example

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 for field settings, output and lifetime rules.