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 item to the 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 auto sort field index.
|
int |
getBaseFieldIndex()
Represents the base field for a custom calculation.
|
int |
getBaseIndex()
Represents the PivotField index in the base PivotFields.
|
int |
getBaseItemIndex()
Represents the item in the base field for a custom calculation.
|
int |
getBaseItemPosition()
Represents the item in the base field for a custom calculation.
|
java.lang.String |
getCalculatedFieldFormula()
Get the formula string of the specified calculated field .
|
short |
getCurrentPageItem()
Represents the current page item showing for the page field (valid only for page fields).
|
int |
getDataDisplayFormat()
Represents how to display the values contained in a data field.
|
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.
|
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 base item count of this pivot field.
|
java.lang.String[] |
getItems()
Get all base items;
|
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.
|
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
|
boolean |
getSubtotals(int subtotalType)
Indicates whether showing specified subtotal.
|
void |
groupBy(CustomPiovtFieldGroupItem[] customGroupItems,
boolean newField)
Custom group the field.
|
void |
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
|
void |
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)
Indicates whether the specific PivotItem is hidden.
|
boolean |
isHiddenItemDetail(int index)
Indicates whether the specific PivotItem is hidden detail.
|
boolean |
isIncludeNewItemsInFilter()
indicates whether the field can include new items in manual filter
The default value is false.
|
boolean |
isInsertPageBreaksBetweenItems()
indicates whether the field can insert page breaks between items
insert page break after each item
The default value is false.
|
boolean |
isMultipleItemSelectionAllowed()
indicates whether the field can have multiple items
selected in the page field
The default value is false.
|
boolean |
isRepeatItemLabels()
indicates whether the field can repeat items labels
The default value is false.
|
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 auto sort field index.
|
void |
setAutoSubtotals(boolean value)
Indicates whether the specified field shows automatic subtotals.
|
void |
setBaseFieldIndex(int value)
Represents the base field for a custom calculation.
|
void |
setBaseIndex(int value)
Represents the PivotField index in the base PivotFields.
|
void |
setBaseItemIndex(int value)
Represents the item in the base field for a custom calculation.
|
void |
setBaseItemPosition(int value)
Represents the item in the base field for a custom calculation.
|
void |
setCurrentPageItem(short value)
Represents the current page item showing for the page field (valid only for page fields).
|
void |
setDataDisplayFormat(int value)
Represents how to display the values contained in a data field.
|
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 the field can include new items in manual filter
The default value is false.
|
void |
setInsertBlankRow(boolean value)
Indicates whether inserting blank line after each item.
|
void |
setInsertPageBreaksBetweenItems(boolean value)
indicates whether the field can insert page breaks between items
insert page break after each item
The default value is false.
|
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 the field can repeat items labels
The default value is false.
|
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 |
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 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 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 void 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 void 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 void groupBy(CustomPiovtFieldGroupItem[] customGroupItems, boolean newField)
customGroupItems - The custom group items.newField - Indicates whether adding a new field to the pivottablepublic void ungroup()
public boolean isCalculatedField()
public java.lang.String getCalculatedFieldFormula()
public int getBaseIndex()
public void setBaseIndex(int value)
public int getPosition()
PivotField in the region.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 boolean getNonAutoSortDefault()
public void setNonAutoSortDefault(boolean value)
public boolean isAutoSort()
public void setAutoSort(boolean value)
public boolean isAscendSort()
public void setAscendSort(boolean value)
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 int getDataDisplayFormat()
public void setDataDisplayFormat(int value)
public int getBaseFieldIndex()
public void setBaseFieldIndex(int value)
public int getBaseItemPosition()
See PivotItemPosition.
public void setBaseItemPosition(int value)
See PivotItemPosition.
public int getBaseItemIndex()
public void setBaseItemIndex(int value)
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 the PivotItems is hiddenpublic 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 item's formulapublic 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 2001-2023. All Rights Reserved.