Add Pivot Connection
Possible Usage Scenarios
If you want to associate slicer and pivot table in Excel, you need to right-click slicer and select “Report Connections…” item. In the option list, you can operate on the check box. Similarly, if you want to associate slicer and pivot table using Aspose.Cells API programmatically, please use the Slicer.AddPivotConnection(PivotTable pivot) method. It will associate slicer and pivot table.
Associate Slicer and PivotTable
The following sample code loads the sample Excel file that contains an existing slicer. It accesses the Slicer and then associates Slicer and PivotTable. Finally, it saves the workbook as output Excel file.
Sample Code
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Load sample Excel file containing slicer. | |
Workbook wb = new Workbook("add-pivot-connection .xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Access the first PivotTable inside the PivotTable collection. | |
PivotTable pivottable = ws.PivotTables[0]; | |
// Access the first slicer inside the slicer collection. | |
Slicer slicer = ws.Slicers[0]; | |
//Adds PivotTable connection. | |
slicer.AddPivotConnection(pivottable); | |
wb.Save("add-pivot-connection-out.xlsx"); |