Hitta och uppdatera de inbäddade eller underordnade pivottabellerna i föräldrapivottabellen

Möjliga användningsscenario

Ibland använder en pivottabell en annan pivottabell som datakälla, så det kallas en underordnad pivottabell eller inbäddad pivottabell. Du kan hitta de underordnade pivottablerna i en föräldrapivottabell med hjälp av PivotTable.getChildren() metoden.

Hitta och uppdatera de inbäddade eller underordnade pivottabellerna i föräldrapivottabellen

Följande kodexempel laddar provexfilsnamn som innehåller tre pivot-tabeller. De nedre två pivot-tabellerna är barnen till ovanstående pivot-tabell som visas i denna skärmdump. Koden hittar barnpivot-tabellen med hjälp av PivotTable.getChildren() metoden och uppdaterar dem en efter en.

todo:image_alt_text

Exempelkod

// 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();
}