添加数据透视连接

可能的使用场景

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

关联切片器和数据透视表

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

示例代码

// Load sample Excel file containing slicer.
Workbook wb = new Workbook("add-pivot-connection .xlsx");
// 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);
//Adds PivotTable connection.
slicer.addPivotConnection(pivottable);
wb.save("add-pivot-connection-out.xlsx");