使用Node.js通过C++添加数据透视连接
Contents
[
Hide
]
可能的使用场景
如果您想在Excel中关联切片器和数据透视表,右键点击切片器并选择“报告连接…”项。在选项列表中,您可以操作复选框。同样地,如果您想通过Aspose.Cells API编程方式关联切片器和数据透视表,请使用Slicer.addPivotConnection(PivotTable pivot)方法。它将关联切片器和数据透视表。
关联切片器和数据透视表
以下示例代码加载了包含现有切片器的示例Excel文件。它访问切片器,然后将切片器与数据透视表关联,最后将工作簿保存为输出Excel文件。
示例代码
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "add-pivot-connection.xlsx");
// Load sample Excel file containing slicer.
const workbook = new AsposeCells.Workbook(filePath);
// Access first worksheet.
const worksheet = workbook.getWorksheets().get(0);
// Access the first PivotTable inside the PivotTable collection.
const pivotTable = worksheet.getPivotTables().get(0);
// Access the first slicer inside the slicer collection.
const slicer = worksheet.getSlicers().get(0);
// Adds PivotTable connection.
slicer.addPivotConnection(pivotTable);
workbook.save(path.join(dataDir, "add-pivot-connection-out.xlsx"));