java.lang.Object
CollectionBase
com.aspose.cells.PivotTableCollection
- All Implemented Interfaces:
- java.lang.Iterable
public class PivotTableCollection
- extends CollectionBase
Represents the collection of all the PivotTable objects on the specified worksheet.
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");
//Add PivotFilter
int index = pivot.getPivotFilters().add(0, PivotFilterType.COUNT);
PivotFilter filter = pivot.getPivotFilters().get(index);
filter.getAutoFilter().filterTop10(0, false, false, 2);
//Add PivotFormatCondition
int formatIndex = pivot.getPivotFormatConditions().add();
PivotFormatCondition pfc = pivot.getPivotFormatConditions().get(formatIndex);
FormatConditionCollection fcc = pfc.getFormatConditions();
fcc.addArea(pivot.getDataBodyRange());
int idx = fcc.addCondition(FormatConditionType.CELL_VALUE);
FormatCondition fc = fcc.get(idx);
fc.setFormula1("100");
fc.setOperator(OperatorType.GREATER_OR_EQUAL);
fc.getStyle().setBackgroundColor(Color.getRed());
pivot.refreshData();
pivot.calculateData();
//do your business
book.save("out.xlsx");
|
Property Getters/Setters Summary |
int | getCount() | → inherited from com.aspose.cells.CollectionBase
|
| |
PivotTable | get(int) | |
|
Gets the PivotTable report by index.
|
PivotTable | get(int, int) | |
|
Gets the PivotTable report by pivottable's position.
|
PivotTable | get(java.lang.String) | |
|
Gets the PivotTable report by pivottable's name.
|
|
Method Summary |
int | add(PivotTable pivotTable, int row, int column, java.lang.String tableName) | |
|
Adds a new PivotTable Object to the collection from another PivotTable.
|
int | add(PivotTable pivotTable, java.lang.String destCellName, java.lang.String tableName) | |
|
Adds a new PivotTable Object to the collection from another PivotTable.
|
int | add(java.lang.Object value) | → inherited from com.aspose.cells.CollectionBase
|
| Reserved for internal use. |
int | add(java.lang.String sourceData, int row, int column, java.lang.String tableName) | |
|
Adds a new PivotTable cache to a PivotCaches collection.
|
int | add(java.lang.String sourceData, int row, int column, java.lang.String tableName, boolean useSameSource) | |
|
Adds a new PivotTable cache to a PivotCaches collection.
|
int | add(java.lang.String sourceData, java.lang.String destCellName, java.lang.String tableName) | |
|
Adds a new PivotTable cache to a PivotCaches collection.
|
int | add(java.lang.String sourceData, java.lang.String destCellName, java.lang.String tableName, boolean useSameSource) | |
|
Adds a new PivotTable cache to a PivotCaches collection.
|
int | add(java.lang.String[] sourceData, boolean isAutoPage, PivotPageFields pageFields, int row, int column, java.lang.String tableName) | |
|
Adds a new PivotTable Object to the collection with multiple consolidation ranges as data source.
|
int | add(java.lang.String[] sourceData, boolean isAutoPage, PivotPageFields pageFields, java.lang.String destCellName, java.lang.String tableName) | |
|
Adds a new PivotTable Object to the collection with multiple consolidation ranges as data source.
|
void | clear() | |
|
Clear all pivot tables.
|
boolean | contains(java.lang.Object value) | → inherited from com.aspose.cells.CollectionBase
|
| Reserved for internal use. |
void | dispose() | |
|
Performs application-defined tasks associated with freeing, releasing, or
resetting unmanaged resources.
|
int | indexOf(java.lang.Object value) | → inherited from com.aspose.cells.CollectionBase
|
| Reserved for internal use. |
java.util.Iterator | iterator() | → inherited from com.aspose.cells.CollectionBase
|
| |
void | remove(PivotTable pivotTable) | |
|
Deletes the specified PivotTable and delete the PivotTable data
|
void | remove(PivotTable pivotTable, boolean keepData) | |
|
Deletes the specified PivotTable
|
void | removeAt(int index) | |
|
Deletes the PivotTable at the specified index and delete the PivotTable data
|
void | removeAt(int index, boolean keepData) | |
|
Deletes the PivotTable at the specified index
|
|
Property Getters/Setters Detail |
getCount | → inherited from com.aspose.cells.CollectionBase
|
public int getCount()
|
-
-
Gets the PivotTable report by index.
-
Gets the PivotTable report by pivottable's name.
-
Gets the PivotTable report by pivottable's position.
dispose | |
public void dispose() |
-
Performs application-defined tasks associated with freeing, releasing, or
resetting unmanaged resources.
add | |
public int add(java.lang.String sourceData, java.lang.String destCellName, java.lang.String tableName) |
-
Adds a new PivotTable cache to a PivotCaches collection.
- Parameters:
sourceData - The data for the new PivotTable cache.destCellName - The cell in the upper-left corner of the PivotTable report's destination range.tableName - The name of the new PivotTable report.
- Returns:
- The new added cache index.
add | |
public int add(java.lang.String sourceData, java.lang.String destCellName, java.lang.String tableName, boolean useSameSource) |
-
Adds a new PivotTable cache to a PivotCaches collection.
- Parameters:
sourceData - The data for the new PivotTable cache.destCellName - The cell in the upper-left corner of the PivotTable report's destination range.tableName - The name of the new PivotTable report.useSameSource - Indicates whether using same data source when another existing pivot table has used this data source.
If the property is true, it will save memory.
- Returns:
- The new added cache index.
add | |
public int add(java.lang.String sourceData, int row, int column, java.lang.String tableName) |
-
Adds a new PivotTable cache to a PivotCaches collection.
- Parameters:
sourceData - The data cell range for the new PivotTable.Example : Sheet1!A1:C8row - Row index of the cell in the upper-left corner of the PivotTable report's destination range.column - Column index of the cell in the upper-left corner of the PivotTable report's destination range.tableName - The name of the new PivotTable report.
- Returns:
- The new added cache index.
add | |
public int add(java.lang.String sourceData, int row, int column, java.lang.String tableName, boolean useSameSource) |
-
Adds a new PivotTable cache to a PivotCaches collection.
- Parameters:
sourceData - The data cell range for the new PivotTable.Example : Sheet1!A1:C8row - Row index of the cell in the upper-left corner of the PivotTable report's destination range.column - Column index of the cell in the upper-left corner of the PivotTable report's destination range.tableName - The name of the new PivotTable report.useSameSource - Indicates whether using same data source when another existing pivot table has used this data source.
If the property is true, it will save memory.
- Returns:
- The new added cache index.
add | |
public int add(PivotTable pivotTable, java.lang.String destCellName, java.lang.String tableName) |
-
Adds a new PivotTable Object to the collection from another PivotTable.
- Parameters:
pivotTable - The source pivotTable.destCellName - The cell in the upper-left corner of the PivotTable report's destination range.tableName - The name of the new PivotTable report.
- Returns:
- The new added PivotTable index.
add | |
public int add(PivotTable pivotTable, int row, int column, java.lang.String tableName) |
-
Adds a new PivotTable Object to the collection from another PivotTable.
- Parameters:
pivotTable - The source pivotTable.row - Row index of the cell in the upper-left corner of the PivotTable report's destination range.column - Column index of the cell in the upper-left corner of the PivotTable report's destination range.tableName - The name of the new PivotTable report.
- Returns:
- The new added PivotTable index.
add | |
public int add(java.lang.String[] sourceData, boolean isAutoPage, PivotPageFields pageFields, java.lang.String destCellName, java.lang.String tableName) |
-
Adds a new PivotTable Object to the collection with multiple consolidation ranges as data source.
- Parameters:
sourceData - The multiple consolidation ranges,such as {"Sheet1!A1:C8","Sheet2!A1:B8"}isAutoPage - Whether auto create a single page field.
If true,the following param pageFields will be ignored.
pageFields - The pivot page field items.
destCellName - destCellName The name of the new PivotTable report.tableName - the name of the new PivotTable report.
- Returns:
- The new added PivotTable index.
add | |
public int add(java.lang.String[] sourceData, boolean isAutoPage, PivotPageFields pageFields, int row, int column, java.lang.String tableName) |
-
Adds a new PivotTable Object to the collection with multiple consolidation ranges as data source.
- Parameters:
sourceData - The multiple consolidation ranges,such as {"Sheet1!A1:C8","Sheet2!A1:B8"}isAutoPage - Whether auto create a single page field.
If true,the following param pageFields will be ignoredpageFields - The pivot page field items.
row - Row index of the cell in the upper-left corner of the PivotTable report's destination range.column - Column index of the cell in the upper-left corner of the PivotTable report's destination range.tableName - The name of the new PivotTable report.
- Returns:
- The new added PivotTable index.
clear | |
public void clear() |
-
Clear all pivot tables.
-
Deletes the specified PivotTable and delete the PivotTable data
- Parameters:
pivotTable - PivotTable object
remove | |
public void remove(PivotTable pivotTable, boolean keepData) |
-
Deletes the specified PivotTable
- Parameters:
pivotTable - PivotTable objectkeepData - Whether to keep the PivotTable data
removeAt | |
public void removeAt(int index) |
-
Deletes the PivotTable at the specified index and delete the PivotTable data
- Parameters:
index - the position index in PivotTable collection
removeAt | |
public void removeAt(int index, boolean keepData) |
-
Deletes the PivotTable at the specified index
- Parameters:
index - the position index in PivotTable collectionkeepData - Whether to keep the PivotTable data
iterator | → inherited from com.aspose.cells.CollectionBase
|
public java.util.Iterator iterator() |
-
contains | → inherited from com.aspose.cells.CollectionBase
|
public boolean contains(java.lang.Object value) |
- Reserved for internal use.
add | → inherited from com.aspose.cells.CollectionBase
|
public int add(java.lang.Object value) |
- Reserved for internal use.
indexOf | → inherited from com.aspose.cells.CollectionBase
|
public int indexOf(java.lang.Object value) |
- Reserved for internal use.
See Also:
Aspose.Cells Documentation - the home page for the Aspose.Cells Product Documentation.
Aspose.Cells Support Forum - our preferred method of support.