Remove Pivot Connection with C++

Possible Usage Scenarios

If you want to disassociate a slicer from a pivot table in Excel, you need to right‑click the slicer and select Report Connections…. In the options list, you can modify the check box. Similarly, if you want to disassociate a slicer from a pivot table programmatically using the Aspose.Cells API, please use the Slicer.RemovePivotConnection(PivotTable pivot) method. It will disassociate the slicer from the pivot table.

Disassociate slicer and pivot table

The following sample code loads the sample Excel file that contains an existing slicer. It accesses the slicer and then disassociates the slicer from the pivot table. Finally, it saves the workbook as output Excel file.

Sample Code

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Load sample Excel file containing a slicer
    U16String inputFilePath = u"remove-pivot-connection.xlsx";
    Workbook wb(inputFilePath);

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