python - 如何使用 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]))
推荐阅读
- python - 检查列表中的所有值是否大于某个数字 x 且小于 y?
- vue.js - 如何在主 vue 组件之外访问导入的 vue 组件的实例?
- ms-access - 如何远程连接到Access数据库?
- xcode - 将 SDK 设置为 12.1
- cmd - Azure Devops (VSTS) - 在控制台中以管理员身份启动构建代理(交互模式)
- javascript - 如何制作输出 html 的 wordpress 块?
- regex - 正则表达式:匹配第一次出现的:
- php - 如何在 swagger-lume 中描述请求中的数组数组
- vim - 如何将vim的输出重定向到终端?
- python - 熊猫:从 SettingWithCopyWarning 到 loc 和 iloc