gpt4 book ai didi

Python:刷新工作表中的数据透视表

转载 作者:太空狗 更新时间:2023-10-29 20:31:32 25 4
gpt4 key购买 nike

<分区>

我正在构建一个 python 脚本,它允许我打开 Excel 2010 工作表并将其打印出来。

我已经完成了大部分工作

import win32com.client

office = win32com.client.Dispatch("Excel.Application")
wb = office.Workbooks.Open(r"path\to\excel\file\to\print.xlsm")

count = wb.Sheets.Count
for i in range(count):
ws = wb.Worksheets[i]

pivotCount = ws.PivotTables().Count
for j in range(1, pivotCount+1):
#TODO code to refresh each pivot table

ws.PrintOut()
print "Worksheet: %s - has been sent to the printer" % (ws.Name)

如您所见,我仍然缺少工作表中数据透视表的刷新。

刷新的VBA代码是:

ActiveSheet.PivotTables(1).PivotCache.Refresh

我似乎无法将代码分解为 python win32com 语法。我得到的最接近的是:

wb.WorkSheets(5).PivotTables(1).PivotCache.Refresh

给出 <bound method CDispatch.Refresh of <COMObject PivotCache>>但工作表中没有结果。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com