简体   繁体   中英

Python update excel spreadsheet links

I have python code to open excel, then save and exit but I am struggling to find the right python code for a key interim step - once python opens my spreadsheet what is the code to "edit links" and then "update values" before saving the spreadsheet? Please note this is not the same as wb.RefreshAll() My code with the missing interim step is below:

import win32com.client
xlapp = win32com.client.DispatchEx("Excel.Application")
wb = xlapp.workbooks.open('C:/myfilepathname/test.xlsm')
#what code goes here to select edit links and update them all.

wb.Save()
xlapp.Quit()

Thanks

So I decided instead to create a macro in the existing spreadsheet that updates the external links and to call that macro from python as follows:

import os
import win32com.client
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(Filename="C:/myfilepathname/test.xlsm", ReadOnly=1)
xl.Visible = True
xl.Application.Run("mymacro")
xl.ActiveWorkbook.Save()
xl.Quit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM