It is possible to update an external link by value. The sheetproperty sheet.LinkMode controls this. It is equivalent to the formula to value for selected cells issued in the GUI.
This action is irreversible, once the document is stored. To keep the sourcefiles dynamic, the procedure is therefore to load the source document(s), set the linkmode to VALUE for all sheets, and store the source file(s) with a suffix.
In the target file, the right external links needs to be inserted, using the source filenames with suffix. (first run createUpdateSource to create the suffix files)
At any time, run linkByValue to obtain the most updated results from the source files and update all links in the target file. @GRMOTT , FYI
import uno
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
dispatcher = smgr.createInstanceWithContext(“com.sun.star.frame.DispatchHelper”, ctx)
StarDesktop = smgr.createInstanceWithContext(“com.sun.star.frame.Desktop”, ctx)
from com.sun.star.sheet.SheetLinkMode import VALUE as LINKVALUE, NORMAL as LINKNORMAL
def createOrUpdateSource():
sFiles = [ “~/source.ods”, “~/target.ods”]
for i, sFile in enumerate(sFiles[:-1]):
sText = uno.systemPathToFileUrl( sFile)
oDoc = StarDesktop.loadComponentFromURL(sText,"_blank",0,() )
oSheets = oDoc.getSheets()
for j in range(oSheets.Count):
oSheet = oSheets.getByIndex(j)
oSheet.LinkMode =LINKVALUE
n = sText.rfind(".")
sText = sText[:n] + "_tmp" + sText[n:]
oDoc.storeAsURL( sText , () )
oDoc.close( True )
return sFiles
def linkByValue():
sFiles = createOrUpdateSource()
sText = sFiles[len(sFiles)-1]
sText = uno.systemPathToFileUrl( sText)
oDoc = StarDesktop.loadComponentFromURL(sText,"_blank",0,() )
oAreaLinks = oDoc.AreaLinks
for i in range(oAreaLinks.Count):
oLink = oAreaLinks.getByIndex(i)
oLink.refresh()
msgbox("done")