Refresh Excel External Data with Python

前端 未结 5 1090
北荒
北荒 2020-11-29 08:39

I have an Excel file that I run a Python script on. The Excel file has external data connections that need to be refreshed before the Python script is run. The functionality

5条回答
  •  一整个雨季
    2020-11-29 09:17

    CalculateUntilAsyncQueriesDone() will hold the program and wait until the refresh has completed.

    xlapp = win32com.client.DispatchEx("Excel.Application")
    wb = xlapp.Workbooks.Open()
    wb.RefreshAll()
    xlapp.CalculateUntilAsyncQueriesDone()
    wb.Save()
    xlapp.Quit()
    

提交回复
热议问题