PivotTableFormatCollection.FormatArea

PivotTableFormatCollection.FormatArea method

Formats selected area.

public PivotTableFormat FormatArea(PivotFieldType axisType, int fieldPosition, 
    PivotFieldSubtotalType subtotalType, PivotTableSelectionType selectionType, bool isGrandRow, 
    bool isGrandColumn, Style style)
ParameterTypeDescription
axisTypePivotFieldTypeThe region of the PivotTable to which this rule applies.
fieldPositionInt32Position of the field within the axis to which this rule applies.
subtotalTypePivotFieldSubtotalTypeThe subtotal filter type of the pivot field
selectionTypePivotTableSelectionTypeIndicates how to select data.
isGrandRowBooleanIndicates whether selecting grand total rows.
isGrandColumnBooleanIndicates whether selecting grand total columns.
styleStyleThe style which appies to the area of the pivot table.

Examples

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

namespace AsposeCellsExamples
{
    public class PivotTableFormatCollectionMethodFormatAreaWithPivotFieldTypeInt32PivotFieldSDemo
    {
        public static void Run()
        {
            // Create a workbook from source file
            Workbook workbook = new Workbook("example.xlsx");
            
            // Access the pivot table
            PivotTable pt = workbook.Worksheets["PIVOT_VBA_SUBTOTALS"].PivotTables[0];
            
            // Create a style for formatting
            Style style = workbook.CreateStyle();
            style.SetBorder(BorderType.LeftBorder, CellBorderType.Thin, Color.Red);
            style.SetBorder(BorderType.RightBorder, CellBorderType.Thin, Color.Red);
            style.SetBorder(BorderType.TopBorder, CellBorderType.Thin, Color.Red);
            style.SetBorder(BorderType.BottomBorder, CellBorderType.Thin, Color.Red);
            style.Pattern = BackgroundType.Solid;
            style.ForegroundColor = Color.LightGray;
            style.BackgroundColor = Color.LightGray;

            // Format the pivot table area
            pt.PivotFormats.FormatArea(
                PivotFieldType.Row, 
                0, 
                PivotFieldSubtotalType.Automatic, 
                PivotTableSelectionType.DataAndLabel, 
                false, 
                false, 
                style);

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

See Also