python刷新excel


說明:

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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM