我有一个要求,其中包含多个工作表的 24 个子 excel 文件通过来自一个巨大的主 excel 文件的数据连接进行更新。我正在使用 python 进行自动刷新。
我能够找出代码,但不知何故代码不起作用,只要任何工作表上有任何过滤器。谁能指导我为什么会这样?
非常感谢您的帮助。
谢谢。
以下是我的代码:
import win32com.client
import os
import glob
# import time
# for WorkingFile in os.listdir("C:\\Users\\techy\\OneDrive\\Desktop\\python\\Data_files\\cust-geo"):
File_path=r"U:\Claims\Reporting\Lags-Individual\2021"
os.chdir(File_path)
xlapp = win32com.client.DispatchEx("Excel.Application")
for FileList in glob.glob('*.xlsm'):#getting all the file names from the folder
if not FileList.startswith('~$') :#Filtering out the temp files
print(FileList)
pw_str = 'locked'# password to open the file
wb = xlapp.Workbooks.Open(File_path+"\\"+FileList)
wb.Unprotect(pw_str)
# wb.UnprotectSharing(pw_str)
xlapp.DisplayAlerts = False
wb.RefreshAll() #1st refresh for power query data connection
print(File_path+"\\"+FileList)
wb.RefreshAll() # 2nd refresh for pivot tables
xlapp.CalculateUntilAsyncQueriesDone()
wb.Save()
wb.Close()
# time.sleep(20)
xlapp.Quit()