Aspose::Cells::Pivot::PivotField class

PivotField class

Represents a field in a PivotTable report.

class PivotField

Methods

MethodDescription
AddCalculatedItem(const U16String& name, const U16String& formula)Add a calculated formula item to the pivot field.
AddCalculatedItem(const char16_t* name, const char16_t* formula)Add a calculated formula item to the pivot field.
ClearFilter()Clears filter setting on this pivot field.
FilterByDate(PivotFilterType type, const Date& dateTime1, const Date& dateTime2)Filters by date values of row or column pivot field.
FilterByLabel(PivotFilterType type, const U16String& label1, const U16String& label2)Filters by captions of row or column pivot field.
FilterByLabel(PivotFilterType type, const char16_t* label1, const char16_t* label2)Filters by captions of row or column pivot field.
FilterByValue(int32_t valueFieldIndex, PivotFilterType type, double value1, double value2)Filters by values of data pivot field.
FilterTop10(int32_t valueFieldIndex, PivotFilterType type, bool isTop, int32_t itemCount)Filters by values of data pivot field.
Get_NumberFormat()Represents the custom display format of numbers and dates.
GetAutoShowCount()Represent the number of top or bottom items that are automatically shown in the specified PivotTable field.
GetAutoShowField()Represents auto show field index. -1 means PivotField itself. It should be the index of the data fields.
GetAutoSortField()Represents the index of field which is auto sorted. -1 means PivotField itself,others means the position of the data fields.
GetBaseIndex()Represents the index in the source pivot fields.
GetCurrentPageItem()Represents the current selected page item of the page field to filter data. Only valid for page fields.
GetDisplayName()Represents the display name of pivot field in the pivot table view.
GetDragToColumn()Indicates whether the specified field can be dragged to the column position. The default value is true.
GetDragToData()Indicates whether the specified field can be dragged to the values region. The default value is true.
GetDragToHide()Indicates whether the specified field can be dragged to the hide region. The default value is true.
GetDragToPage()Indicates whether the specified field can be dragged to the page position. The default value is true.
GetDragToRow()Indicates whether the specified field can be dragged to the row region. The default value is true.
GetFilters()Gets all pivot filters applied for this pivot field.
GetFormula()Gets the formula of the calculated field . Only works for calculated field.
GetFunction()Represents the function used to summarize this PivotTable data field.
GetGroupSettings()Gets the group settings of the pivot field.
GetInsertBlankRow()Indicates whether to insert a blank line after each item.
GetItemCount()Gets the count of the base items in this pivot field.
GetItems()Get all labels of pivot items in this field.
GetName()Represents the name of PivotField.
GetNonAutoSortDefault()Indicates whether a sort operation that will be applied to this pivot field is an autosort operation or a simple data sort.
GetNumber()Represents the built-in display format of numbers and dates.
GetOriginalItems()Get the original base items;.
GetPivotFilterByType(PivotFilterType type)Gets the pivot filter of the pivot field by type.
GetPivotItems()Gets the pivot items of the pivot field.
GetPosition()Represents the index of PivotField in the region.
GetRegionType()Specifies the region of the PivotTable that this field is displayed.
GetShowAllItems()Indicates whether to display all items in the PivotTable view, even if they don’t contain summary data. The default value is false.
GetShowCompact()Indicates whether to display labels of the next field in the same column on the Pivot Table view.
GetShowInOutlineForm()Indicates whether to layout this field in outline form on the Pivot Table view.
GetShowSubtotalAtTop()Indicates whether to display subtotals at the top or bottom of items when ShowInOutlineForm is true, then.
GetShowValuesSetting()Gets the settings of showing values as when the ShowDataAs calculation is in use.
GetSortSetting()Gets all settings of auto sorting.
GetSubtotals(PivotFieldSubtotalType subtotalType)Indicates whether to show specified subtotal for this pivot field.
GroupBy(double interval, bool newField)Automatically group the field with internal.
GroupBy(const Date& start, const Date& end, const Vector <PivotGroupByType>& groups, double interval, bool firstAsNewField)Group the file by the date group types.
GroupBy(double start, double end, double interval, bool newField)Group the file by number.
GroupBy(const Vector <CustomPiovtFieldGroupItem>& customGroupItems, bool newField)Custom group the field.
HideDetail(bool isHiddenDetail)Sets whether the detail of all PivotItems in a pivot field are hidden. That is collapse/expand this field.
HideItem(int32_t index, bool isHidden)Sets whether the specific PivotItem in a data field is hidden.
HideItem(const U16String& itemValue, bool isHidden)Sets whether the specific PivotItem in a data field is hidden.
HideItem(const char16_t* itemValue, bool isHidden)Sets whether the specific PivotItem in a data field is hidden.
HideItemDetail(int32_t index, bool isHiddenDetail)Sets whether the specific PivotItem in a pivot field is hidden detail.
InitPivotItems()Init the pivot items of the pivot field.
IsAscendShow()Indicates whether the specified PivotTable field is autoshown ascending.
IsAscendSort()Indicates whether the items of this pivot field is autosorted ascending.
IsAutoShow()Indicates whether the specified PivotTable field is automatically shown.
IsAutoSort()Indicates whether the items of this PivotTable field are automatically sorted.
IsAutoSubtotals()Indicates whether the specified field shows automatic subtotals. Default is true.
IsCalculatedField()Indicates whether the this pivot field is calculated field.
IsHiddenItem(int32_t index)Gets whether the specific PivotItem is hidden.
IsHiddenItemDetail(int32_t index)Gets whether to hide the detail of the specific PivotItem..
IsIncludeNewItemsInFilter()Indicates whether to include new items to the field in manual filter. The default value is false.
IsInsertPageBreaksBetweenItems()Indicates whether to insert page breaks after each item. The default value is false.
IsMultipleItemSelectionAllowed()Indicates whether multiple items could be selected in the page field. The default value is false.
IsNull() constChecks whether the implementation object is nullptr.
IsRepeatItemLabels()Indicates whether to repeat labels of the field in the region. The default value is false.
IsValuesField()Indicates whether this field represents values field.
explicit operator bool() constoperator bool()
operator=(const PivotField& src)operator=
PivotField(PivotField_Impl* impl)Constructs from an implementation object.
PivotField(const PivotField& src)Copy constructor.
SetAutoShowCount(int32_t value)Represent the number of top or bottom items that are automatically shown in the specified PivotTable field.
SetAutoShowField(int32_t value)Represents auto show field index. -1 means PivotField itself. It should be the index of the data fields.
SetAutoSortField(int32_t value)Represents the index of field which is auto sorted. -1 means PivotField itself,others means the position of the data fields.
SetBaseIndex(int32_t value)Represents the index in the source pivot fields.
SetCurrentPageItem(int16_t value)Represents the current selected page item of the page field to filter data. Only valid for page fields.
SetDisplayName(const U16String& value)Represents the display name of pivot field in the pivot table view.
SetDisplayName(const char16_t* value)Represents the display name of pivot field in the pivot table view.
SetDragToColumn(bool value)Indicates whether the specified field can be dragged to the column position. The default value is true.
SetDragToData(bool value)Indicates whether the specified field can be dragged to the values region. The default value is true.
SetDragToHide(bool value)Indicates whether the specified field can be dragged to the hide region. The default value is true.
SetDragToPage(bool value)Indicates whether the specified field can be dragged to the page position. The default value is true.
SetDragToRow(bool value)Indicates whether the specified field can be dragged to the row region. The default value is true.
SetFunction(ConsolidationFunction value)Represents the function used to summarize this PivotTable data field.
SetInsertBlankRow(bool value)Indicates whether to insert a blank line after each item.
SetIsAscendShow(bool value)Indicates whether the specified PivotTable field is autoshown ascending.
SetIsAscendSort(bool value)Indicates whether the items of this pivot field is autosorted ascending.
SetIsAutoShow(bool value)Indicates whether the specified PivotTable field is automatically shown.
SetIsAutoSort(bool value)Indicates whether the items of this PivotTable field are automatically sorted.
SetIsAutoSubtotals(bool value)Indicates whether the specified field shows automatic subtotals. Default is true.
SetIsIncludeNewItemsInFilter(bool value)Indicates whether to include new items to the field in manual filter. The default value is false.
SetIsInsertPageBreaksBetweenItems(bool value)Indicates whether to insert page breaks after each item. The default value is false.
SetIsMultipleItemSelectionAllowed(bool value)Indicates whether multiple items could be selected in the page field. The default value is false.
SetIsRepeatItemLabels(bool value)Indicates whether to repeat labels of the field in the region. The default value is false.
SetName(const U16String& value)Represents the name of PivotField.
SetName(const char16_t* value)Represents the name of PivotField.
SetNonAutoSortDefault(bool value)Indicates whether a sort operation that will be applied to this pivot field is an autosort operation or a simple data sort.
SetNumber(int32_t value)Represents the built-in display format of numbers and dates.
SetNumberFormat(const U16String& value)Represents the custom display format of numbers and dates.
SetNumberFormat(const char16_t* value)Represents the custom display format of numbers and dates.
SetShowAllItems(bool value)Indicates whether to display all items in the PivotTable view, even if they don’t contain summary data. The default value is false.
SetShowCompact(bool value)Indicates whether to display labels of the next field in the same column on the Pivot Table view.
SetShowInOutlineForm(bool value)Indicates whether to layout this field in outline form on the Pivot Table view.
SetShowSubtotalAtTop(bool value)Indicates whether to display subtotals at the top or bottom of items when ShowInOutlineForm is true, then.
SetSubtotals(PivotFieldSubtotalType subtotalType, bool shown)Sets how to subtotal the specified field.
ShowValuesAs(PivotFieldDataDisplayFormat displayFormat, int32_t baseField, PivotItemPositionType baseItemPositionType, int32_t baseItem)Shows values of data field as different display format when the ShowDataAs calculation is in use.
SortBy(SortOrder sortType, int32_t fieldSortedBy)Sorts this pivot field.
SortBy(SortOrder sortType, int32_t fieldSortedBy, PivotLineType dataType, const U16String& cellName)Sorts this pivot field.
SortBy(SortOrder sortType, int32_t fieldSortedBy, PivotLineType dataType, const char16_t* cellName)Sorts this pivot field.
Ungroup()Ungroup the pivot field.
~PivotField()Destructor.

Fields

FieldDescription
_implThe implementation object.

Examples

Aspose::Cells::Startup();
Workbook book;
Worksheet sheet = book.GetWorksheets().Get(0);
Cells cells = sheet.GetCells();
cells.Get(0, 0).PutValue(u"fruit");
cells.Get(1, 0).PutValue(u"grape");
cells.Get(2, 0).PutValue(u"blueberry");
cells.Get(3, 0).PutValue(u"kiwi");
cells.Get(4, 0).PutValue(u"cherry");
cells.Get(5, 0).PutValue(u"grape");
cells.Get(6, 0).PutValue(u"blueberry");
cells.Get(7, 0).PutValue(u"kiwi");
cells.Get(8, 0).PutValue(u"cherry");

cells.Get(0, 1).PutValue(u"year");
cells.Get(1, 1).PutValue(2020);
cells.Get(2, 1).PutValue(2020);
cells.Get(3, 1).PutValue(2020);
cells.Get(4, 1).PutValue(2020);
cells.Get(5, 1).PutValue(2021);
cells.Get(6, 1).PutValue(2021);
cells.Get(7, 1).PutValue(2021);
cells.Get(8, 1).PutValue(2021);

cells.Get(0, 2).PutValue(u"amount");
cells.Get(1, 2).PutValue(50);
cells.Get(2, 2).PutValue(60);
cells.Get(3, 2).PutValue(70);
cells.Get(4, 2).PutValue(80);
cells.Get(5, 2).PutValue(90);
cells.Get(6, 2).PutValue(100);
cells.Get(7, 2).PutValue(110);
cells.Get(8, 2).PutValue(120);

PivotTableCollection pivots = sheet.GetPivotTables();

int pivotIndex = pivots.Add(u"=Sheet1!A1:C9", u"A12", u"TestPivotTable");
PivotTable pivot = pivots.Get(pivotIndex);
pivot.AddFieldToArea(PivotFieldType::Row, u"fruit");
pivot.AddFieldToArea(PivotFieldType::Column, u"year");
pivot.AddFieldToArea(PivotFieldType::Data, u"amount");

pivot.SetPivotTableStyleType(PivotTableStyleType::PivotTableStyleMedium10);

//Change PivotField's attributes
PivotField rowField = pivot.GetRowFields().Get(0);
rowField.SetDisplayName(u"custom display name");

pivot.RefreshData();
pivot.CalculateData();


book.Save("out.xlsx");

Aspose::Cells::Cleanup();

See Also