PivotField class
PivotField class
Represents a field in a PivotTable report.
The PivotField type exposes the following members:
Properties
Property | Description |
---|---|
pivot_items | Gets the pivot items of the pivot field |
range | Gets the group range of the pivot field |
group_settings | Gets the group settings of the pivot field. |
is_calculated_field | Indicates whether the specified PivotTable field is calculated field. |
base_index | Represents the PivotField index in the base PivotFields. |
position | Represents the index of PivotField in the region. |
name | Represents the name of PivotField. |
display_name | Represents the PivotField display name. |
is_auto_subtotals | Indicates whether the specified field shows automatic subtotals. Default is true. |
drag_to_column | Indicates whether the specified field can be dragged to the column position. The default value is true. |
drag_to_hide | Indicates whether the specified field can be dragged to the hide position. The default value is true. |
drag_to_row | Indicates whether the specified field can be dragged to the row position. The default value is true. |
drag_to_page | Indicates whether the specified field can be dragged to the page position. The default value is true. |
drag_to_data | Indicates whether the specified field can be dragged to the data position. The default value is true. |
is_multiple_item_selection_allowed | indicates whether the field can have multiple items selected in the page field The default value is false. |
is_repeat_item_labels | Indicates whether repeating labels of the field in the region. The default value is false. |
is_include_new_items_in_filter | Indicates whether including new items to the field in manual filter. The default value is false. |
is_insert_page_breaks_between_items | Indicates whether inserting page breaks after each item. The default value is false. |
show_all_items | 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. |
non_auto_sort_default | Indicates whether a sort operation that will be applied to this pivot field is an autosort operation or a simple data sort. |
is_auto_sort | Indicates whether the specified PivotTable field is automatically sorted. |
is_ascend_sort | Indicates whether the specified PivotTable field is autosorted ascending. |
sort_setting | Gets all settings of auto sorting |
auto_sort_field | Represents the index of field which is auto sorted. -1 means PivotField itself,others means the position of the data fields. |
is_auto_show | Indicates whether the specified PivotTable field is automatically shown,only valid for excel 2003. |
is_ascend_show | Indicates whether the specified PivotTable field is autoshown ascending. |
auto_show_count | Represent the number of top or bottom items that are automatically shown in the specified PivotTable field. |
auto_show_field | Represents auto show field index. -1 means PivotField itself. It should be the index of the data fields. |
function | Represents the function used to summarize the PivotTable data field. |
show_values_setting | Gets the settings of showing values as when the ShowDataAs calculation is in use. |
data_display_format | Represents how to display the values in a data field of the pivot report. |
base_field_index | Represents the base field for a custom calculation when the ShowDataAs calculation is in use. |
base_item_position | Represents the item in the base field for a custom calculation when the ShowDataAs calculation is in use. Valid only for data fields. Because PivotItemPosition.Custom is only for read,if you need to set PivotItemPosition.Custom, please set PivotField.BaseItemIndex attribute. |
base_item_index | Represents the item in the base field for a custom calculation when the ShowDataAs calculation is in use. Valid only for data fields. |
current_page_item | Represents the current page item showing for the page field (valid only for page fields). |
number | Represents the built-in display format of numbers and dates. |
insert_blank_row | Indicates whether inserting blank line after each item. |
show_subtotal_at_top | when ShowInOutlineForm is true, then display subtotals at the top of the list of items instead of at the bottom |
show_in_outline_form | Indicates whether layout this field in outline form on the Pivot Table view |
number_format | Represents the custom display format of numbers and dates. |
items | Get all labels of pivot items in this field. |
original_items | Get the original base items; |
item_count | Gets the count of the base items in this pivot field. |
show_compact | Indicates whether display labels from the next field in the same column on the Pivot Table view |
Methods
Method | Description |
---|---|
group_by | Automatically group the field with internal |
group_by | Group the file by the date group types. |
group_by | Group the file by number. |
group_by | Custom group the field. |
sort_by | Sorts this pivot field. |
sort_by | Sorts this pivot field. |
hide_item | Sets whether the specific PivotItem in a data field is hidden. |
hide_item | Sets whether the specific PivotItem in a data field is hidden. |
get_pivot_filter_by_type | Gets the pivot filter of the pivot field by type |
get_pivot_filters | Gets the pivot filters of the pivot field |
get_filters | Gets all pivot filters of this pivot field. |
init_pivot_items | Init the pivot items of the pivot field |
ungroup | Ungroup the pivot field. |
get_calculated_field_formula | Get the formula string of the specified calculated field . |
set_subtotals | Sets whether the specified field shows that subtotals. |
get_subtotals | Indicates whether showing specified subtotal. |
show_values_as | Shows values of data field as different display format when the ShowDataAs calculation is in use. |
is_hidden_item | Gets whether the specific PivotItem is hidden. |
is_hidden_item_detail | Gets whether hidding the detail of the specific PivotItem.. |
hide_item_detail | Sets whether the specific PivotItem in a pivot field is hidden detail. |
hide_detail | Sets whether the PivotItems in a pivot field is hidden detail.That is collapse/expand this field. |
add_calculated_item | Add a calculated formula item to the pivot field. |
Example
from aspose.cells import Workbook
from aspose.cells.pivot import PivotFieldType, PivotTableStyleType
book = Workbook()
sheet = book.worksheets[0]
cells = sheet.cells
cells.get(0, 0).value = "fruit"
cells.get(1, 0).value = "grape"
cells.get(2, 0).value = "blueberry"
cells.get(3, 0).value = "kiwi"
cells.get(4, 0).value = "cherry"
cells.get(5, 0).value = "grape"
cells.get(6, 0).value = "blueberry"
cells.get(7, 0).value = "kiwi"
cells.get(8, 0).value = "cherry"
cells.get(0, 1).value = "year"
cells.get(1, 1).value = 2020
cells.get(2, 1).value = 2020
cells.get(3, 1).value = 2020
cells.get(4, 1).value = 2020
cells.get(5, 1).value = 2021
cells.get(6, 1).value = 2021
cells.get(7, 1).value = 2021
cells.get(8, 1).value = 2021
cells.get(0, 2).value = "amount"
cells.get(1, 2).value = 50
cells.get(2, 2).value = 60
cells.get(3, 2).value = 70
cells.get(4, 2).value = 80
cells.get(5, 2).value = 90
cells.get(6, 2).value = 100
cells.get(7, 2).value = 110
cells.get(8, 2).value = 120
pivots = sheet.pivot_tables
pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable")
pivot = pivots[pivotIndex]
pivot.add_field_to_area(PivotFieldType.ROW, "fruit")
pivot.add_field_to_area(PivotFieldType.COLUMN, "year")
pivot.add_field_to_area(PivotFieldType.DATA, "amount")
pivot.pivot_table_style_type = PivotTableStyleType.PIVOT_TABLE_STYLE_MEDIUM10
# Change PivotField's attributes
rowField = pivot.row_fields[0]
rowField.display_name = "custom display name"
pivot.refresh_data()
pivot.calculate_data()
# do your business
book.save("out.xlsx")
See Also
- module
aspose.cells.pivot
- class
PivotField