public class PivotTableCollection extends CollectionBase
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");
| Modifier and Type | Method and Description |
|---|---|
int |
add(PivotTable pivotTable,
int row,
int column,
java.lang.String tableName)
Adds a new PivotTable based on another PivotTable.
|
int |
add(PivotTable pivotTable,
java.lang.String destCellName,
java.lang.String tableName)
Adds a new PivotTable based on another PivotTable.
|
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.
|
int |
add(java.lang.String sourceData,
int row,
int column,
java.lang.String tableName)
Adds a new PivotTable.
|
int |
add(java.lang.String sourceData,
int row,
int column,
java.lang.String tableName,
boolean useSameSource)
Adds a new PivotTable.
|
int |
add(java.lang.String sourceData,
int row,
int column,
java.lang.String tableName,
boolean useSameSource,
boolean isXlsClassic)
Adds a new PivotTable.
|
int |
add(java.lang.String sourceData,
java.lang.String destCellName,
java.lang.String tableName)
Adds a new PivotTable.
|
int |
add(java.lang.String sourceData,
java.lang.String destCellName,
java.lang.String tableName,
boolean useSameSource)
Adds a new PivotTable.
|
int |
add(java.lang.String sourceData,
java.lang.String cell,
java.lang.String tableName,
boolean useSameSource,
boolean isXlsClassic)
Adds a new PivotTable.
|
void |
clear()
Clear all pivot tables.
|
void |
dispose()
Performs application-defined tasks associated with freeing, releasing, or
resetting unmanaged resources.
|
PivotTable |
get(int index)
Gets the PivotTable report by index.
|
PivotTable |
get(int row,
int column)
Gets the PivotTable report by pivottable's position.
|
PivotTable |
get(java.lang.String name)
Gets the PivotTable report by pivottable's name.
|
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
|
public void dispose()
public int add(java.lang.String sourceData,
java.lang.String destCellName,
java.lang.String tableName)
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.public int add(java.lang.String sourceData,
java.lang.String destCellName,
java.lang.String tableName,
boolean useSameSource)
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.public int add(java.lang.String sourceData,
int row,
int column,
java.lang.String tableName)
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.public int add(java.lang.String sourceData,
int row,
int column,
java.lang.String tableName,
boolean useSameSource)
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.public int add(java.lang.String sourceData,
int row,
int column,
java.lang.String tableName,
boolean useSameSource,
boolean isXlsClassic)
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.isXlsClassic - Indicates whether add classic pivot table of Excel 97-2003.public int add(java.lang.String sourceData,
java.lang.String cell,
java.lang.String tableName,
boolean useSameSource,
boolean isXlsClassic)
sourceData - The data cell range for the new PivotTable.Example : Sheet1!A1:C8cell - 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.isXlsClassic - Indicates whether add classic pivot table of Excel 97-2003.public int add(PivotTable pivotTable, java.lang.String destCellName, java.lang.String tableName)
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.public int add(PivotTable pivotTable, int row, int column, java.lang.String tableName)
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.public int add(java.lang.String[] sourceData,
boolean isAutoPage,
PivotPageFields pageFields,
java.lang.String destCellName,
java.lang.String tableName)
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.public int add(java.lang.String[] sourceData,
boolean isAutoPage,
PivotPageFields pageFields,
int row,
int column,
java.lang.String tableName)
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.public PivotTable get(int index)
get in class CollectionBaseindex - Specified position index.public PivotTable get(java.lang.String name)
public PivotTable get(int row, int column)
public void clear()
clear in class CollectionBasepublic void remove(PivotTable pivotTable)
pivotTable - PivotTable objectpublic void remove(PivotTable pivotTable, boolean keepData)
pivotTable - PivotTable objectkeepData - Whether to keep the PivotTable datapublic void removeAt(int index)
removeAt in class CollectionBaseindex - the position index in PivotTable collectionpublic void removeAt(int index,
boolean keepData)
index - the position index in PivotTable collectionkeepData - Whether to keep the PivotTable dataSee 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.