I am working with pywin32, workbooks for Excel. I have some charts in a sheet that i have to save. The thing is that there's a slicer in this sheet that permit to filter on a certain variable. I didn't find pywin32 docs for it and i do not have any clue here on how i can (or can't) do it.. Thanks
Asked
Active
Viewed 2,447 times
2
-
Pywin32 is basically a very thin wrapper of python that allows us to interact with COM objects and automate Windows applications with python. The power of this approach is that you can pretty much do anything that a Microsoft Application can do through python. So, you can examine the Microsoft API documentation for the [Slicer](https://learn.microsoft.com/en-us/office/vba/api/excel.slicer) and I suspect that should be exposed to you. – David Zemens Jun 25 '19 at 13:45
2 Answers
1
there is reference to Office objects. For slicers https://learn.microsoft.com/en-us/office/vba/api/excel.pivottable.slicers, be aware that slicer is an element of slicers collection
from win32com.client import Dispatch
xl = Dispatch("Excel.Application")
wb = xl.Workbooks.Open("your_file.xlsx")
sl = wb.SlicerCaches("your_slicer")

Przemek
- 11
- 2
0
Apparently in Excel, there is a program within it that could record anything you click so if you want to manipulate the filter/slicer, you can right click the element, and then choose "Assign Macro". Then you can click away as it records your clicks. Once youre done, you can view it by again choosing "Assign Macro" and a pop-up window will be available and you can choose your_filter/slicer_name_Click and it will provid you the VBA code. All you have to do is change it so it fits python format or you can implement it like this.

ihaveaquestion
- 53
- 6