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 setting 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 PivotField index in the base PivotFields.
GetCurrentPageItem()Represents the current page item showing for the page field (valid only for page fields).
GetDisplayName()Represents the PivotField display name.
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 data position. The default value is true.
GetDragToHide()Indicates whether the specified field can be dragged to the hide position. 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 position. The default value is true.
GetFilters()Gets all pivot filters of this pivot field.
GetFormula()Gets formula of the calculated field .
GetFunction()Represents the function used to summarize the PivotTable data field.
GetGroupSettings()Gets the group settings of the pivot field.
GetInsertBlankRow()Indicates whether inserting 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 all items displays in the PivotTable report, even if they don’t contain summary data. show items with no data The default value is false.
GetShowCompact()Indicates whether display labels from the next field in the same column on the Pivot Table view.
GetShowInOutlineForm()Indicates whether layout this field in outline form on the Pivot Table view.
GetShowSubtotalAtTop()when ShowInOutlineForm is true, then display subtotals at the top of the list of items instead of at the bottom
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 showing specified subtotal.
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 PivotItems in a pivot field is hidden detail.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 specified PivotTable field is autosorted ascending.
IsAutoShow()Indicates whether the specified PivotTable field is automatically shown,only valid for excel 2003.
IsAutoSort()Indicates whether the specified PivotTable field is automatically sorted.
IsAutoSubtotals()Indicates whether the specified field shows automatic subtotals. Default is true.
IsCalculatedField()Indicates whether the specified PivotTable field is calculated field.
IsHiddenItem(int32_t index)Gets whether the specific PivotItem is hidden.
IsHiddenItemDetail(int32_t index)Gets whether hidding the detail of the specific PivotItem..
IsIncludeNewItemsInFilter()Indicates whether including new items to the field in manual filter. The default value is false.
IsInsertPageBreaksBetweenItems()Indicates whether inserting page breaks after each item. The default value is false.
IsMultipleItemSelectionAllowed()indicates whether the field can have multiple items selected in the page field The default value is false.
IsNull() constChecks whether the implementation object is nullptr.
IsRepeatItemLabels()Indicates whether repeating labels of the field in the region. The default value is false.
IsValueFields()Indicates whether this field represents values fields.
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 PivotField index in the base PivotFields.
SetCurrentPageItem(int16_t value)Represents the current page item showing for the page field (valid only for page fields).
SetDisplayName(const U16String& value)Represents the PivotField display name.
SetDisplayName(const char16_t* value)Represents the PivotField display name.
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 data position. The default value is true.
SetDragToHide(bool value)Indicates whether the specified field can be dragged to the hide position. 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 position. The default value is true.
SetFunction(ConsolidationFunction value)Represents the function used to summarize the PivotTable data field.
SetInsertBlankRow(bool value)Indicates whether inserting blank line after each item.
SetIsAscendShow(bool value)Indicates whether the specified PivotTable field is autoshown ascending.
SetIsAscendSort(bool value)Indicates whether the specified PivotTable field is autosorted ascending.
SetIsAutoShow(bool value)Indicates whether the specified PivotTable field is automatically shown,only valid for excel 2003.
SetIsAutoSort(bool value)Indicates whether the specified PivotTable field is automatically sorted.
SetIsAutoSubtotals(bool value)Indicates whether the specified field shows automatic subtotals. Default is true.
SetIsIncludeNewItemsInFilter(bool value)Indicates whether including new items to the field in manual filter. The default value is false.
SetIsInsertPageBreaksBetweenItems(bool value)Indicates whether inserting page breaks after each item. The default value is false.
SetIsMultipleItemSelectionAllowed(bool value)indicates whether the field can have multiple items selected in the page field The default value is false.
SetIsRepeatItemLabels(bool value)Indicates whether repeating 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 all items displays in the PivotTable report, even if they don’t contain summary data. show items with no data The default value is false.
SetShowCompact(bool value)Indicates whether display labels from the next field in the same column on the Pivot Table view.
SetShowInOutlineForm(bool value)Indicates whether layout this field in outline form on the Pivot Table view.
SetShowSubtotalAtTop(bool value)when ShowInOutlineForm is true, then display subtotals at the top of the list of items instead of at the bottom
SetSubtotals(PivotFieldSubtotalType subtotalType, bool shown)Sets whether the specified field shows that subtotals.
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