Do you need slicers for connecting your chart object/ Pivot tables?
Here is a complete solution to your problem.
I have used win32com.client library to create Pivot tables, Slicers and to establish slicers connection.
Code to create Pivot table:
def new_pivot_table(Field_Name,j,Cache,charttype,top,left):
PivotTable = PivotCache.CreatePivotTable(TableDestination='Sheet1!R150C'+j,
TableName ='ReportPivotTable'+Cache, DefaultVersion=win32c.xlPivotTableVersion14)
PivotTable.PivotFields(Field_Name).Orientation = win32c.xlRowField
PivotTable.PivotFields(Field_Name).Position = 1
DataField = PivotTable.AddDataField(PivotTable.PivotFields('count'))
S = PivotTable._PivotSelect(2881,4)
chart = Sheet2.Shapes.AddChart2(314,charttype,top,left, 50, 60)
ChartObj = chart.Chart
return PivotTable,ChartObj
Code to create slicers
def create_Slicer(Pivottable,Field_Name,Cache):
S = Pivottable._PivotSelect(2881,4)
SLcache = wb.SlicerCaches.Add2(Pivottable,Field_Name,"ProdCatSlicerCache"+Cache)
SL=SLcache.Slicers.Add(SlicerDestination=wb.ActiveSheet,Name="ProdCatSlicer"+Cache,Top=65+int(Cache)*30,Left=800,Width=210,Height=70)
return SLcache
Connecting Slicers to each of the Pivot tables/ Charts:
def slicer_connect(SLcache):
for j in range(1,9,1):
k=str(j)
SLcache.PivotTables.AddPivotTable(wb.ActiveSheet.PivotTables("ReportPivotTable"+k))