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 item to the pivot field.
AddCalculatedItem(const char16_t* name, const char16_t* formula)Add a calculated item to the 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 auto sort field index. -1 means PivotField itself,others means the position of the data fields.
GetBaseFieldIndex()Represents the base field for a custom calculation.
GetBaseIndex()Represents the PivotField index in the base PivotFields.
GetBaseItemIndex()Represents the item in the base field for a custom calculation. Valid only for data fields.
GetBaseItemPosition()Represents the item in the base field for a custom calculation. Valid only for data fields. Because PivotItemPosition.Custom is only for read,if you need to set PivotItemPosition.Custom, please set PivotField.BaseItemIndex attribute.
GetCalculatedFieldFormula()Get the formula string of the specified calculated field .
GetCurrentPageItem()Represents the current page item showing for the page field (valid only for page fields).
GetDataDisplayFormat()Represents how to display the values contained in a data field.
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.
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 base item count of this pivot field.
GetItems()Get all base items;.
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.
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
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)Indicates whether the specific PivotItem is hidden.
IsHiddenItemDetail(int32_t index)Indicates whether the specific PivotItem is hidden detail.
IsIncludeNewItemsInFilter()indicates whether the field can include new items in manual filter The default value is false.
IsInsertPageBreaksBetweenItems()indicates whether the field can insert page breaks between items insert page break 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 the field can repeat items labels The default value is false.
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 auto sort field index. -1 means PivotField itself,others means the position of the data fields.
SetBaseFieldIndex(int32_t value)Represents the base field for a custom calculation.
SetBaseIndex(int32_t value)Represents the PivotField index in the base PivotFields.
SetBaseItemIndex(int32_t value)Represents the item in the base field for a custom calculation. Valid only for data fields.
SetBaseItemPosition(PivotItemPosition value)Represents the item in the base field for a custom calculation. Valid only for data fields. Because PivotItemPosition.Custom is only for read,if you need to set PivotItemPosition.Custom, please set PivotField.BaseItemIndex attribute.
SetCurrentPageItem(int16_t value)Represents the current page item showing for the page field (valid only for page fields).
SetDataDisplayFormat(PivotFieldDataDisplayFormat value)Represents how to display the values contained in a data field.
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 the field can include new items in manual filter The default value is false.
SetIsInsertPageBreaksBetweenItems(bool value)indicates whether the field can insert page breaks between items insert page break 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 the field can repeat items labels 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.
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