以下代码刷新所有数据连接,但是无法刷新数据透视表缓存。因此,我尝试添加另一段代码来刷新每张工作表上的数据透视表缓存,但这也失败了。你能看看这个吗?
xlapp = win32.DispatchEx("Excel.Application")
xlapp.Visible = True
wb = xlapp.Workbooks.Open(src)
wb.RefreshAll()
xlapp.CalculateUntilAsyncQueriesDone()
count = wb.Sheets.Count
for i in range(count):
ws = wb.Worksheets[i+1]
pivotCount = ws.PivotTables().Count
for j in range(pivotCount):
ws.PivotTables(j+1).PivotCache().Refresh()