用C++移除透视连接
Contents
[
Hide
]
可能的使用场景
如果要在Excel中取消切片器与数据透视表的关联,您需要右键单击切片器并选择"Report Connections…“选项。在选项列表中,您可以操作复选框。同样,如果要使用Aspose.Cells API编程方式取消切片器与数据透视表的关联,请使用Slicer.RemovePivotConnection(PivotTable pivot)方法。这将取消切片器与数据透视表的关联。
取消切片器与数据透视表的关联
以下示例代码加载了包含现有切片器的sample Excel file。它访问切片器,然后取消切片器与数据透视表的关联,最后将工作簿保存为output Excel file。
示例代码
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Load sample Excel file containing slicer
U16String inputFilePath = u"remove-pivot-connection.xlsx";
Workbook wb(inputFilePath);
// 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
U16String outputFilePath = u"remove-pivot-connection-out.xlsx";
wb.Save(outputFilePath);
std::cout << "Pivot connection removed successfully!" << std::endl;
Aspose::Cells::Cleanup();
}