說明:
excel連接數據庫,然后python控制excel刷新。
代碼展示
import os import time from win32com.client import Dispatch def refreash(path_file): os.system('taskkill /IM EXCEL.exe /F') # 殺死正在執行的excel程序,慎用,可不用 xlapp = Dispatch('Excel.Application') xlapp.visible = 1 wkb = xlapp.Workbooks.open(path_file) wkb.RefreshAll() time.sleep(20) # 如果表格中刷新時間過長,或者有很多計算,建議沉睡一會 wkb.Save() wkb.Close(1) xlapp.quit() print('自動更新結束') if __name__ == '__main__': path_file = r'E:\測試\ceshi.xlsx' refreash(path_file)
