Hitta och uppdatera pivottabellerna för kapslade eller barn i överordnade pivottabeller
Contents
[
Hide
]
Möjliga användningsscenarier
Ibland använder en pivottabell en annan pivottabell som datakälla, så den kallas en underordnad pivottabell eller kapslad pivottabell. Du kan hitta de underordnade pivottabellerna för en överordnad pivottabell med hjälp avPivotTable.getChildren() metod.
Hitta och uppdatera pivottabellerna för kapslade eller barn i överordnade pivottabeller
Följande exempelkod laddarexempel på Excel-filsom innehåller tre pivottabeller. De två nedre pivottabellerna är underordnade av ovanstående pivottabell som visas i den här skärmdumpen. Koden hittar pivottabellen för barn med hjälp avPivotTable.getChildren() och uppdaterar dem sedan en efter en.
Exempelkod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Load sample Excel file | |
Workbook wb = new Workbook("sampleFindAndRefreshNestedOrChildrenPivotTables.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access third pivot table | |
PivotTable ptParent = ws.getPivotTables().get(2); | |
//Access the children of the parent pivot table | |
PivotTable[] ptChildren = ptParent.getChildren(); | |
//Refresh all the children pivot table | |
int count = ptChildren.length; | |
for (int idx = 0; idx < count; idx++) | |
{ | |
//Access the child pivot table | |
PivotTable ptChild = ptChildren[idx]; | |
//Refresh the child pivot table | |
ptChild.refreshData(); | |
ptChild.calculateData(); | |
} |