Hitta och uppdatera de inbäddade eller barnpivot tabellerna för en föräldrapivot tabell med C++
Contents
[
Hide
]
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.
Exempelkod
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Load sample Excel file
U16String inputFilePath = u"sampleFindAndRefreshNestedOrChildrenPivotTables.xlsx";
Workbook wb(inputFilePath);
// 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
Vector<PivotTable> ptChildren = ptParent.GetChildren();
// Refresh all the children pivot table
int count = ptChildren.GetLength();
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();
}
std::cout << "Children pivot tables refreshed successfully!" << std::endl;
Aspose::Cells::Cleanup();
}