public class PivotField
extends java.lang.Object
Example
Workbook book = new Workbook();
Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();
cells.get(0, 0).setValue("fruit");
cells.get(1, 0).setValue("grape");
cells.get(2, 0).setValue("blueberry");
cells.get(3, 0).setValue("kiwi");
cells.get(4, 0).setValue("cherry");
cells.get(5, 0).setValue("grape");
cells.get(6, 0).setValue("blueberry");
cells.get(7, 0).setValue("kiwi");
cells.get(8, 0).setValue("cherry");
cells.get(0, 1).setValue("year");
cells.get(1, 1).setValue(2020);
cells.get(2, 1).setValue(2020);
cells.get(3, 1).setValue(2020);
cells.get(4, 1).setValue(2020);
cells.get(5, 1).setValue(2021);
cells.get(6, 1).setValue(2021);
cells.get(7, 1).setValue(2021);
cells.get(8, 1).setValue(2021);
cells.get(0, 2).setValue("amount");
cells.get(1, 2).setValue(50);
cells.get(2, 2).setValue(60);
cells.get(3, 2).setValue(70);
cells.get(4, 2).setValue(80);
cells.get(5, 2).setValue(90);
cells.get(6, 2).setValue(100);
cells.get(7, 2).setValue(110);
cells.get(8, 2).setValue(120);
PivotTableCollection pivots = sheet.getPivotTables();
int pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots.get(pivotIndex);
pivot.addFieldToArea(PivotFieldType.ROW, "fruit");
pivot.addFieldToArea(PivotFieldType.COLUMN, "year");
pivot.addFieldToArea(PivotFieldType.DATA, "amount");
pivot.setPivotTableStyleType(PivotTableStyleType.PIVOT_TABLE_STYLE_MEDIUM_10);
//Change PivotField's attributes
PivotField rowField = pivot.getRowFields().get(0);
rowField.setDisplayName("custom display name");
pivot.refreshData();
pivot.calculateData();
//do your business
book.save("out.xlsx");
| Modifier and Type | Method and Description |
|---|---|
void |
addCalculatedItem(java.lang.String name,
java.lang.String formula)
Add a calculated formula item to the pivot field.
|
void |
clearFilter()
Clears filter setting on this pivot field.
|
PivotFilter |
filterByDate(int type,
DateTime dateTime1,
DateTime dateTime2)
Filters by date setting of row or column pivot field.
|
PivotFilter |
filterByLabel(int type,
java.lang.String label1,
java.lang.String label2)
Filters by captions of row or column pivot field.
|
PivotFilter |
filterByValue(int valueFieldIndex,
int type,
double value1,
double value2)
Filters by values of data pivot field.
|
PivotFilter |
filterTop10(int valueFieldIndex,
int type,
boolean isTop,
int itemCount)
Filters by values of data pivot field.
|
int |
getAutoShowCount()
Represent the number of top or bottom items
that are automatically shown in the specified PivotTable field.
|
int |
getAutoShowField()
Represents auto show field index.
|
int |
getAutoSortField()
Represents the index of field which is auto sorted.
|
int |
getBaseFieldIndex()
Deprecated.
Use PivotField.ShowValuesSetting.BaseFieldIndex property instead.
|
int |
getBaseIndex()
Represents the PivotField index in the base PivotFields.
|
int |
getBaseItemIndex()
Deprecated.
Use PivotField.ShowValuesSetting.BaseItemIndex property instead.
|
int |
getBaseItemPosition()
Deprecated.
Use PivotField.ShowValuesSetting.BaseItemPositionType property instead.
|
java.lang.String |
getCalculatedFieldFormula()
Deprecated.
Use PivotField.GetFormula() method instead.
|
short |
getCurrentPageItem()
Represents the current page item showing for the page field (valid only for page fields).
|
int |
getDataDisplayFormat()
Deprecated.
Use PivotField.ShowValuesSetting.CalculationType property instead.
|
java.lang.String |
getDisplayName()
Represents the PivotField display name.
|
boolean |
getDragToColumn()
Indicates whether the specified field can be dragged to the column position.
|
boolean |
getDragToData()
Indicates whether the specified field can be dragged to the data position.
|
boolean |
getDragToHide()
Indicates whether the specified field can be dragged to the hide position.
|
boolean |
getDragToPage()
Indicates whether the specified field can be dragged to the page position.
|
boolean |
getDragToRow()
Indicates whether the specified field can be dragged to the row position.
|
PivotFilter[] |
getFilters()
Gets all pivot filters of this pivot field.
|
java.lang.String |
getFormula()
Gets formula of the calculated field .
|
int |
getFunction()
Represents the function used to summarize the PivotTable data field.
|
PivotFieldGroupSettings |
getGroupSettings()
Gets the group settings of the pivot field.
|
boolean |
getInsertBlankRow()
Indicates whether inserting blank line after each item.
|
int |
getItemCount()
Gets the count of the base items in this pivot field.
|
java.lang.String[] |
getItems()
Get all labels of pivot items in this field.
|
java.lang.String |
getName()
Represents the name of PivotField.
|
boolean |
getNonAutoSortDefault()
Indicates whether a sort operation that will be applied to this pivot field is an autosort operation or a simple data sort.
|
int |
getNumber()
Represents the built-in display format of numbers and dates.
|
java.lang.String |
getNumberFormat()
Represents the custom display format of numbers and dates.
|
java.lang.String[] |
getOriginalItems()
Get the original base items;
|
PivotFilter |
getPivotFilterByType(int type)
Gets the pivot filter of the pivot field by type
|
java.util.ArrayList |
getPivotFilters()
Deprecated.
Use PivotField.GetFilters() instead.
|
PivotItemCollection |
getPivotItems()
Gets the pivot items of the pivot field
|
int |
getPosition()
Represents the index of
PivotField in the region. |
SxRng |
getRange()
Deprecated.
Use PivotField.GroupSettings property instead.
|
int |
getRegionType()
Specifies the region of the PivotTable that this field is displayed.
|
boolean |
getShowAllItems()
Indicates whether all items displays in the PivotTable report,
even if they don't contain summary data.
|
boolean |
getShowCompact()
Indicates whether display labels from the next field in the same column on the Pivot Table view
|
boolean |
getShowInOutlineForm()
Indicates whether layout this field in outline form on the Pivot Table view
|
boolean |
getShowSubtotalAtTop()
when ShowInOutlineForm is true, then display subtotals at the top of the list of items instead of at the bottom
|
PivotShowValuesSetting |
getShowValuesSetting()
Gets the settings of showing values as when the ShowDataAs calculation is in use.
|
PivotFieldSortSetting |
getSortSetting()
Gets all settings of auto sorting
|
boolean |
getSubtotals(int subtotalType)
Indicates whether showing specified subtotal.
|
boolean |
groupBy(CustomPiovtFieldGroupItem[] customGroupItems,
boolean newField)
Custom group the field.
|
boolean |
groupBy(DateTime start,
DateTime end,
int[] groups,
double interval,
boolean firstAsNewField)
Group the file by the date group types.
|
void |
groupBy(double interval,
boolean newField)
Automatically group the field with internal
|
boolean |
groupBy(double start,
double end,
double interval,
boolean newField)
Group the file by number.
|
void |
hideDetail(boolean isHiddenDetail)
Sets whether the PivotItems in a pivot field is hidden detail.That is collapse/expand this field.
|
void |
hideItem(int index,
boolean isHidden)
Sets whether the specific PivotItem in a data field is hidden.
|
void |
hideItem(java.lang.String itemValue,
boolean isHidden)
Sets whether the specific PivotItem in a data field is hidden.
|
void |
hideItemDetail(int index,
boolean isHiddenDetail)
Sets whether the specific PivotItem in a pivot field is hidden detail.
|
void |
initPivotItems()
Init the pivot items of the pivot field
|
boolean |
isAscendShow()
Indicates whether the specified PivotTable field is autoshown ascending.
|
boolean |
isAscendSort()
Indicates whether the specified PivotTable field is autosorted ascending.
|
boolean |
isAutoShow()
Indicates whether the specified PivotTable field is automatically shown,only valid for excel 2003.
|
boolean |
isAutoSort()
Indicates whether the specified PivotTable field is automatically sorted.
|
boolean |
isAutoSubtotals()
Indicates whether the specified field shows automatic subtotals.
|
boolean |
isCalculatedField()
Indicates whether the specified PivotTable field is calculated field.
|
boolean |
isHiddenItem(int index)
Gets whether the specific PivotItem is hidden.
|
boolean |
isHiddenItemDetail(int index)
Gets whether hidding the detail of the specific PivotItem..
|
boolean |
isIncludeNewItemsInFilter()
Indicates whether including new items to the field in manual filter.
|
boolean |
isInsertPageBreaksBetweenItems()
Indicates whether inserting page breaks after each item.
|
boolean |
isMultipleItemSelectionAllowed()
indicates whether the field can have multiple items
selected in the page field
The default value is false.
|
boolean |
isRepeatItemLabels()
Indicates whether repeating labels of the field in the region.
|
boolean |
isValueFields()
Indicates whether this field represents values fields.
|
void |
setAscendShow(boolean value)
Indicates whether the specified PivotTable field is autoshown ascending.
|
void |
setAscendSort(boolean value)
Indicates whether the specified PivotTable field is autosorted ascending.
|
void |
setAutoShow(boolean value)
Indicates whether the specified PivotTable field is automatically shown,only valid for excel 2003.
|
void |
setAutoShowCount(int value)
Represent the number of top or bottom items
that are automatically shown in the specified PivotTable field.
|
void |
setAutoShowField(int value)
Represents auto show field index.
|
void |
setAutoSort(boolean value)
Indicates whether the specified PivotTable field is automatically sorted.
|
void |
setAutoSortField(int value)
Represents the index of field which is auto sorted.
|
void |
setAutoSubtotals(boolean value)
Indicates whether the specified field shows automatic subtotals.
|
void |
setBaseFieldIndex(int value)
Deprecated.
Use PivotField.ShowValuesSetting.BaseFieldIndex property instead.
|
void |
setBaseIndex(int value)
Represents the PivotField index in the base PivotFields.
|
void |
setBaseItemIndex(int value)
Deprecated.
Use PivotField.ShowValuesSetting.BaseItemIndex property instead.
|
void |
setBaseItemPosition(int value)
Deprecated.
Use PivotField.ShowValuesSetting.BaseItemPositionType property instead.
|
void |
setCurrentPageItem(short value)
Represents the current page item showing for the page field (valid only for page fields).
|
void |
setDataDisplayFormat(int value)
Deprecated.
Use PivotField.ShowValuesSetting.CalculationType property instead.
|
void |
setDisplayName(java.lang.String value)
Represents the PivotField display name.
|
void |
setDragToColumn(boolean value)
Indicates whether the specified field can be dragged to the column position.
|
void |
setDragToData(boolean value)
Indicates whether the specified field can be dragged to the data position.
|
void |
setDragToHide(boolean value)
Indicates whether the specified field can be dragged to the hide position.
|
void |
setDragToPage(boolean value)
Indicates whether the specified field can be dragged to the page position.
|
void |
setDragToRow(boolean value)
Indicates whether the specified field can be dragged to the row position.
|
void |
setFunction(int value)
Represents the function used to summarize the PivotTable data field.
|
void |
setIncludeNewItemsInFilter(boolean value)
Indicates whether including new items to the field in manual filter.
|
void |
setInsertBlankRow(boolean value)
Indicates whether inserting blank line after each item.
|
void |
setInsertPageBreaksBetweenItems(boolean value)
Indicates whether inserting page breaks after each item.
|
void |
setMultipleItemSelectionAllowed(boolean value)
indicates whether the field can have multiple items
selected in the page field
The default value is false.
|
void |
setName(java.lang.String value)
Represents the name of PivotField.
|
void |
setNonAutoSortDefault(boolean value)
Indicates whether a sort operation that will be applied to this pivot field is an autosort operation or a simple data sort.
|
void |
setNumber(int value)
Represents the built-in display format of numbers and dates.
|
void |
setNumberFormat(java.lang.String value)
Represents the custom display format of numbers and dates.
|
void |
setRepeatItemLabels(boolean value)
Indicates whether repeating labels of the field in the region.
|
void |
setShowAllItems(boolean value)
Indicates whether all items displays in the PivotTable report,
even if they don't contain summary data.
|
void |
setShowCompact(boolean value)
Indicates whether display labels from the next field in the same column on the Pivot Table view
|
void |
setShowInOutlineForm(boolean value)
Indicates whether layout this field in outline form on the Pivot Table view
|
void |
setShowSubtotalAtTop(boolean value)
when ShowInOutlineForm is true, then display subtotals at the top of the list of items instead of at the bottom
|
void |
setSubtotals(int subtotalType,
boolean shown)
Sets whether the specified field shows that subtotals.
|
void |
showValuesAs(int displayFormat,
int baseField,
int baseItemPositionType,
int baseItem)
Shows values of data field as different display format when the ShowDataAs calculation is in use.
|
void |
sortBy(int sortType,
int fieldSortedBy)
Sorts this pivot field.
|
void |
sortBy(int sortType,
int fieldSortedBy,
int dataType,
java.lang.String cellName)
Sorts this pivot field.
|
void |
ungroup()
Ungroup the pivot field.
|
public PivotItemCollection getPivotItems()
public SxRng getRange()
Remarks
NOTE: This method is now obsolete. Instead, please use PivotField.GroupSettings property. This method will be removed 12 months later since October 2023. Aspose apologizes for any inconvenience you may have experienced.public PivotFieldGroupSettings getGroupSettings()
Remarks
If this field is not grouped, Null will be returned.public void initPivotItems()
public void groupBy(double interval,
boolean newField)
interval - The internal of group.
Automatic value will be assigned if it's zero,newField - Indicates whether adding a new field to the pivottable.public boolean groupBy(DateTime start, DateTime end, int[] groups, double interval, boolean firstAsNewField)
start - The start datetimeend - The end of datetimegroups - PivotGroupByType. Group typesinterval - The intervalfirstAsNewField - Indicates whether adding a new field to the pivottable.
Only for the first group item.public boolean groupBy(double start,
double end,
double interval,
boolean newField)
start - The start valueend - The end of valueinterval - The intervalnewField - Indicates whether adding a new field to the pivottablepublic boolean groupBy(CustomPiovtFieldGroupItem[] customGroupItems, boolean newField)
customGroupItems - The custom group items.newField - Indicates whether adding a new field to the pivottablepublic void ungroup()
public PivotFilter getPivotFilterByType(int type)
public java.util.ArrayList getPivotFilters()
Remarks
NOTE: This method is now obsolete. Instead, please use PivotField.GetFilters() method. This method will be removed 12 months later since November 2023. Aspose apologizes for any inconvenience you may have experienced.public PivotFilter[] getFilters()
public void clearFilter()
public PivotFilter filterTop10(int valueFieldIndex, int type, boolean isTop, int itemCount)
valueFieldIndex - The index of data field in the data region.type - PivotFilterType. The type of filtering data. Only can be Count,Sum and Percent.isTop - Indicates whether filter from top or bottomitemCount - The item countpublic PivotFilter filterByValue(int valueFieldIndex, int type, double value1, double value2)
valueFieldIndex - The index of value field in the value region.type - PivotFilterType. The type of filtering data.value1 - The value of filter conditionvalue2 - The upper-bound value of between filter conditionpublic PivotFilter filterByLabel(int type, java.lang.String label1, java.lang.String label2)
type - PivotFilterType. The type of filtering data.label1 - The label of filter conditionlabel2 - The upper-bound label of between filter conditionpublic PivotFilter filterByDate(int type, DateTime dateTime1, DateTime dateTime2)
type - PivotFilterType. The type of filtering data.dateTime1 - The date label of filter conditiondateTime2 - The upper-bound date label of between filter conditionpublic boolean isCalculatedField()
public java.lang.String getCalculatedFieldFormula()
Remarks
NOTE: This method is now obsolete. Instead, please use PivotField.GetFormula() method. This method will be removed 12 months later since August 2024. Aspose apologizes for any inconvenience you may have experienced.public java.lang.String getFormula()
public boolean isValueFields()
public int getBaseIndex()
public void setBaseIndex(int value)
public int getPosition()
PivotField in the region.public int getRegionType()
See PivotFieldType.
public java.lang.String getName()
public void setName(java.lang.String value)
public java.lang.String getDisplayName()
public void setDisplayName(java.lang.String value)
public void setSubtotals(int subtotalType,
boolean shown)
subtotalType - PivotFieldSubtotalType. subtotals type.shown - whether the specified field shows that subtotals.public boolean getSubtotals(int subtotalType)
subtotalType - PivotFieldSubtotalType. subtotal type.public boolean isAutoSubtotals()
public void setAutoSubtotals(boolean value)
public boolean getDragToColumn()
public void setDragToColumn(boolean value)
public boolean getDragToHide()
public void setDragToHide(boolean value)
public boolean getDragToRow()
public void setDragToRow(boolean value)
public boolean getDragToPage()
public void setDragToPage(boolean value)
public boolean getDragToData()
public void setDragToData(boolean value)
public boolean isMultipleItemSelectionAllowed()
public void setMultipleItemSelectionAllowed(boolean value)
public boolean isRepeatItemLabels()
public void setRepeatItemLabels(boolean value)
public boolean isIncludeNewItemsInFilter()
public void setIncludeNewItemsInFilter(boolean value)
public boolean isInsertPageBreaksBetweenItems()
public void setInsertPageBreaksBetweenItems(boolean value)
public boolean getShowAllItems()
public void setShowAllItems(boolean value)
public void sortBy(int sortType,
int fieldSortedBy)
sortType - SortOrder. The type of sorting this field.fieldSortedBy - The index of pivot field sorted by.
-1 means sorting by data labels of this field, others mean the index of data field sorted by.public void sortBy(int sortType,
int fieldSortedBy,
int dataType,
java.lang.String cellName)
sortType - SortOrder. The type of sorting this field.fieldSortedBy - The index of pivot field sorted by.
-1 means sorting by data labels of this field, others mean the index of data field sorted by.dataType - PivotLineType. The type of data sorted by.cellName - Sort by values in the row or columnpublic boolean getNonAutoSortDefault()
public void setNonAutoSortDefault(boolean value)
public boolean isAutoSort()
public void setAutoSort(boolean value)
public boolean isAscendSort()
public void setAscendSort(boolean value)
public PivotFieldSortSetting getSortSetting()
public int getAutoSortField()
public void setAutoSortField(int value)
public boolean isAutoShow()
public void setAutoShow(boolean value)
public boolean isAscendShow()
public void setAscendShow(boolean value)
public int getAutoShowCount()
public void setAutoShowCount(int value)
public int getAutoShowField()
public void setAutoShowField(int value)
public int getFunction()
public void setFunction(int value)
public void showValuesAs(int displayFormat,
int baseField,
int baseItemPositionType,
int baseItem)
Remarks
Only for data field.displayFormat - PivotFieldDataDisplayFormat. The data display format type.baseField - The index to the field which ShowDataAs calculation bases on.baseItemPositionType - PivotItemPositionType.
The position type of base iteam.baseItem - The index to the base item which ShowDataAs calculation bases on.
Only works when baseItemPositionType is custom.public PivotShowValuesSetting getShowValuesSetting()
public int getDataDisplayFormat()
See PivotFieldDataDisplayFormat.
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.CalculationType property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public void setDataDisplayFormat(int value)
See PivotFieldDataDisplayFormat.
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.CalculationType property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public int getBaseFieldIndex()
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.BaseFieldIndex property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public void setBaseFieldIndex(int value)
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.BaseFieldIndex property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public int getBaseItemPosition()
See PivotItemPosition.
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.BaseItemPositionType property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public void setBaseItemPosition(int value)
See PivotItemPosition.
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.BaseItemPositionType property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public int getBaseItemIndex()
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.BaseItemIndex property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public void setBaseItemIndex(int value)
Remarks
NOTE: This property is now obsolete. Instead, please use PivotField.ShowValuesSetting.BaseItemIndex property instead. This method will be removed 12 months later since June 2024. Aspose apologizes for any inconvenience you may have experienced.public short getCurrentPageItem()
public void setCurrentPageItem(short value)
public int getNumber()
public void setNumber(int value)
public boolean getInsertBlankRow()
public void setInsertBlankRow(boolean value)
public boolean getShowSubtotalAtTop()
Remarks
Only works when ShowInOutlineForm is true.public void setShowSubtotalAtTop(boolean value)
Remarks
Only works when ShowInOutlineForm is true.public boolean getShowInOutlineForm()
public void setShowInOutlineForm(boolean value)
public java.lang.String getNumberFormat()
public void setNumberFormat(java.lang.String value)
public boolean isHiddenItem(int index)
index - The index of the pivotItem in the pivotField.public void hideItem(int index,
boolean isHidden)
index - the index of the pivotItem in the pivotField.isHidden - whether the specific PivotItem is hiddenpublic boolean isHiddenItemDetail(int index)
index - The index of the pivotItem in the pivotField.public void hideItemDetail(int index,
boolean isHiddenDetail)
index - the index of the pivotItem in the pivotField.isHiddenDetail - whether the specific PivotItem is hiddenpublic void hideDetail(boolean isHiddenDetail)
isHiddenDetail - Whether hide the detail of the pivot field.public void hideItem(java.lang.String itemValue,
boolean isHidden)
itemValue - the value of the pivotItem in the pivotField.isHidden - whether the specific PivotItem is hiddenpublic java.lang.String[] getItems()
public java.lang.String[] getOriginalItems()
public int getItemCount()
public void addCalculatedItem(java.lang.String name,
java.lang.String formula)
Remarks
Only supports to add calculated item to Row/Column field.name - The item's name.formula - The formula of pivot item.public boolean getShowCompact()
public void setShowCompact(boolean value)
See Also:
Aspose.Cells Documentation - the home page for the Aspose.Cells Product Documentation.
Aspose.Cells Support Forum - our preferred method of support.
We guarantee a prompt response to any inquiry!
© Aspose Pty Ltd 2003-2025. All Rights Reserved.