Refresh Excel External Data with Python

前端 未结 5 1096
北荒
北荒 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:14

    Adding this as an answer since this is the first Google link - the code in the first answer worked but has incorrect capitalization, it should be:

    import win32com.client
    import time
    
    xlapp = win32com.client.DispatchEx("Excel.Application")
    wb = xlapp.Workbooks.Open()
    wb.RefreshAll()
    time.sleep(5)
    wb.Save()
    xlapp.Quit()
    

提交回复
热议问题