Enum PivotAreaType

PivotAreaType enumeration

Indicates the type of rule being used to describe an area or aspect of the PivotTable.

public enum PivotAreaType

Values

NameValueDescription
None0No Pivot area.
Normal1Represents a header or item.
Data2Represents something in the data area.
All3Represents the whole PivotTable.
Origin4Represents the blank cells at the top-left of the PivotTable (top-right for RTL sheets).
Button5Represents a field button.
TopRight6Represents the blank cells at the top-right of the PivotTable (top-left for RTL sheets).

Examples

[C#]

using Aspose.Cells;
using Aspose.Cells.Pivot;
using System;

namespace Demos
{
    public class PivotAreaTypeDemo
    {
        public static void PivotAreaTypeExample()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();

            // Add a new worksheet to the workbook
            Worksheet worksheet = workbook.Worksheets[0];

            // Add sample data to the worksheet
            worksheet.Cells["A1"].PutValue("Product");
            worksheet.Cells["A2"].PutValue("Apples");
            worksheet.Cells["A3"].PutValue("Oranges");
            worksheet.Cells["A4"].PutValue("Bananas");

            worksheet.Cells["B1"].PutValue("Sales");
            worksheet.Cells["B2"].PutValue(100);
            worksheet.Cells["B3"].PutValue(150);
            worksheet.Cells["B4"].PutValue(200);

            // Create a PivotTable
            int pivotTableIndex = worksheet.PivotTables.Add("=A1:B4", "D1", "PivotTable1");
            PivotTable pivotTable = worksheet.PivotTables[pivotTableIndex];

            // Add fields to the PivotTable
            pivotTable.AddFieldToArea(PivotFieldType.Row, 0); // Product
            pivotTable.AddFieldToArea(PivotFieldType.Data, 1); // Sales

            // Create a PivotArea for the PivotTable
            PivotArea pivotArea = new PivotArea(pivotTable);
            pivotArea.RuleType = PivotAreaType.Normal;
            pivotArea.OnlyData = true;
            pivotArea.IsRowGrandIncluded = true;

            // Output the PivotArea properties
            Console.WriteLine("Pivot Area Type: " + pivotArea.RuleType);
            Console.WriteLine("Only Data: " + pivotArea.OnlyData);
            Console.WriteLine("Is Row Grand Included: " + pivotArea.IsRowGrandIncluded);

            // Save the workbook
            workbook.Save("PivotAreaTypeExample.xlsx");
        }
    }
}

See Also