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 kod laddar den prov-Eexcelfilen som innehåller tre pivottabeller. De två nedre pivottablerna är barn till den ovanstående pivottabellen som visas i denna skärmdump. Koden hittar de underordnade pivottablerna 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-.NET
//Load sample Excel file
Workbook wb = new Workbook("sampleFindAndRefreshNestedOrChildrenPivotTables.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Access third pivot table
PivotTable ptParent = ws.PivotTables[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();
}