I have a pivot table with a column name asset_name
and with possible filter values like FCG~11J.6::~ABC-01~GF1234567004
, FCG~11J.7::~ABC-03~GF1907505749
, FCG~11J.9::~ABC-04~GF1907505742
etc
I'm trying to apply a filter using below command
pt_ws.PivotTables(pt_name).PivotFields("asset_name").ClearAllFilters()
pt_ws.PivotTables(pt_name).PivotFields("asset_name").PivotFilters.Add(21, None, "ABC-01")
21 = xlCaptionContains(Filters for all captions that contain the specified string). More info XlPivotFilterType enumeration
but it throws an error
File "C:PivotFilters.py", line 35, in Add
ret = self._oleobj_.InvokeTypes(181, LCID, 1, (9, 0), ((3, 1), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Type
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146827284), None)
The current workaround that I'm using is by writing the filter value directly to the cell
pt_ws.Cells(3, 2).Value = "FCG~11J.6::~ABC-01~GF1234567004"
But I would like to use the filter command as it's more flexible because of XlPivotFilterType
Thanks
question from:
https://stackoverflow.com/questions/65840041/excel-pivot-table-filter-using-python-and-win32com