Ta bort pivottabellanslutning med C++
Contents
[
Hide
]
Möjliga användningsscenario
Om du vill avassociera en slicer och en pivottabell i Excel, måste du högerklicka på slicern och välja “Rapportkopplingar…”. I alternativlistan kan du använda kryssrutan. På liknande sätt om du vill avassociera en slicer och pivottabell med Aspose.Cells API programmatiskt, använd Slicer.RemovePivotConnection(PivotTable pivot)-metoden. Den kommer att avassosciera slicern och pivottabellen.
Bryt isär snitt och pivottabell
Följande provkod laddar in provmappen som innehåller en befintlig slicer. Den går igenom slicerna och sedan avassocierar den slicern och pivottabellen. Slutligen sparar den arbetsboken som output Excel-fil.
Exempelkod
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Load sample Excel file containing slicer
U16String inputFilePath = u"remove-pivot-connection.xlsx";
Workbook wb(inputFilePath);
// Access first worksheet
Worksheet ws = wb.GetWorksheets().Get(0);
// Access the first PivotTable inside the PivotTable collection
PivotTable pivottable = ws.GetPivotTables().Get(0);
// Access the first slicer inside the slicer collection
Slicer slicer = ws.GetSlicers().Get(0);
// Remove PivotTable connection
slicer.RemovePivotConnection(pivottable);
// Save the workbook in output XLSX format
U16String outputFilePath = u"remove-pivot-connection-out.xlsx";
wb.Save(outputFilePath);
std::cout << "Pivot connection removed successfully!" << std::endl;
Aspose::Cells::Cleanup();
}