删除数据透视连接

可能的使用场景

如果要在Excel中取消切片器与数据透视表的关联,您需要右键单击切片器并选择"Report Connections…“选项。在选项列表中,您可以操作复选框。同样,如果要使用Aspose.Cells API编程方式取消切片器与数据透视表的关联,请使用Slicer.removePivotConnection(PivotTable pivot)方法。这将取消切片器与数据透视表的关联。

移除切片器

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

示例代码

// Load sample Excel file containing slicer.
Workbook wb = new Workbook("remove-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);
//Remove PivotTable connection.
slicer.removePivotConnection(pivottable);
// Save the workbook in output XLSX format.
wb.save("remove-pivot-connection-out.xlsx");