Add Pivot Table Row and Column Fields in Aspose.Cells for Go via C++
Adding a Field to the Row or Column Region
The PivotTable.AddFieldToArea(PivotFieldType fieldType, U16String fieldName) method moves a base field from the source data into one of the four pivot regions. The fieldType argument accepts one of the following PivotFieldType values.
Row— fields placed vertically on the leftColumn— fields placed horizontally across the topData— fields whose values are aggregatedPage— fields used as report filters Field nesting order matters. AddingCategoryto the row region first and thenItemproduces a pivot whose outer grouping isCategoryand whose inner grouping isItem. Reversing the order reverses the hierarchy.
Pivot Field Subtotals
The PivotField.SetSubtotals(PivotFieldSubtotalType subtotalType, bool shown) method controls which subtotal rows appear for a pivot field. Each call toggles a single subtotal type independently. Passing shown = true displays the subtotal, while shown = false hides it. Because each call only affects one type, calling the method multiple times with different subtotalType values builds a custom subset of subtotals.
The PivotFieldSubtotalType enum defines the available subtotal kinds.
Automatic— Aspose.Cells chooses the default selection (typicallySumfor numeric fields)None— suppress every subtotal rowSumCountAverageMaxMinProductStdDevStdDevpVarVarp
SetSubtotals calls have no visible effect in that case. This article therefore places two row fields (Category outer, Item inner) in every example so the subtotal boundary between each Category group is visible.
Scenario 1 — Automatic (Default) Subtotals
When you do not call SetSubtotals at all, Aspose.Cells applies the Automatic selection to numeric fields. The following example explicitly confirms this behavior by calling SetSubtotals(PivotFieldSubtotalType.Automatic, true) on the outer Category row field.
Scenario 2 — Suppressing All Subtotals (None)
Calling SetSubtotals(PivotFieldSubtotalType.None, true) removes every subtotal row from the pivot, leaving only the field rows and the grand total at the bottom. This is useful when you want the raw grouped data without any summary rows.
Scenario 3 — Custom Subtotal Subset (Sum + Average)
You are not limited to a single subtotal type. Each SetSubtotals call operates independently on one type, so calling the method twice — once with Sum and once with Average — produces a custom subset of two subtotal rows for each Category group.
Recap
Related Articles
- Page Fields in Pivot Tables
- Refreshing Pivot Tables in Aspose.Cells for Go via C++
- Applying Styles to Pivot Tables