添加数据透视连接

可能的使用场景

如果你想在Excel中关联切片器和数据透视表,你需要右键单击切片器,然后选择"报表连接…“项目。在选项列表中,你可以操作复选框。 类似地,如果你想使用Aspose.Cells API以编程方式关联切片器和数据透视表,请使用Slicer.AddPivotConnection(PivotTable pivot) 方法。 它将关联切片器和数据透视表。

关联切片器和数据透视表

以下示例代码加载包含现有切片器的sample Excel file。它访问切片器然后将切片器与数据透视表关联。最后,将工作簿另存为output Excel file

示例代码

// 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");