如何使用 win32com.client 在数据透视表中按日期字段分组

How to Group by Date Field in a PivotTable using win32com.client

过去几个小时我尝试了很多方法,但没有成功。有人请帮助我。

group_dt = pt.PivotFields('Created')
group_dt.LabelRange.Group(Start=True, End=True, Periods=Array(False, False, False, False, True, False, True))

错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-75-0355ab1abb88> in <module>
      1 group_dt = pt.PivotFields('Created')
----> 2 group_dt.LabelRange.Group(Start=True, End=True, Periods=Array(False, False, False, False, True, False, True))

TypeError: 'str' object is not callable

经过大量研究,我找到了使用 win32com.client

对日期字段进行分组的方法
cell = pivot_sheet.Range('B5')
cell.Group(Start=True, End=True, Periods=list([False, False, False, False, True, False, True]))