This quick tutorial guides on how to connect slicer to multiple pivot tables using C#. It has details to set the IDE, a list of steps, and a sample code to get a slicer connected to multiple pivot tables using C#. You will learn the process of creating a workbook from scratch and then perform the complete task using this file.
Steps to Link Slicer to Multiple Pivot Tables using C#
- Set the environment to use Aspose.Cells for .NET for working with a slicer
- Load the license and initialize the workbook class object
- Get a reference to the first sheet and add the header row to it
- Add some sample data for the pivot tables
- Invoke the PivotTables.Add() method to create the first pivot table
- Set the row and data fields for the first pivot
- Create the next pivot table so that the cache can be shared
- Refresh both the pivots to calculate their data
- Add the slicer and use the Slicers.Add() method to connect it to the second pivot table
- Save the workbook on the disk
These steps summarize the process for using one slicer for two pivot tables using C#. Initialize the workbook, get a reference to the first sheet, add a header row and sample data for the pivot tables, create the first pivot table with the desired parameters, and create the next pivot table for sharing the cache. Refresh both the pivot tables to calculate their data, add a slicer and content it to the second pivot table, and save the workbook on the disk.
Code to Use one Slicer for Multiple Pivot Tables using C#
This code demonstrates the process to connect one slicer to multiple pivot tables using C#. Ensure that worksheet indices are correct and fields exist before calling the AddFieldToArea() method. You may use the last row/column instead of the hardcoded “A1:B3” to keep the source range dynamic.
This article has taught us the process of connecting a slicer to multiple pivot tables. To convert an Excel file to the markdown format, refer to the article Convert Excel to Markdown using C#.