Programmatically change and update link to external data

I want to write a macro that updates a sheets link to external data. The data is a table in an HTML-file.

I’ve looked at Document.SheetLink but it seems there is no actual link there altough there is one entry, and I can’t seem to write to that.

I’ve also tried Sheet.Link(url, sheet, filter, filter_options, mode) and it seems that updates some type of link because if the URL is incorrect Calc displays “Link could not be updated” and shows the incorrect link. But if the link is correct nothing changes.

I’m doing this in LibreOffice Basic.

I was on Windows (if that matters) and it seems that a correct URL to a file needs to start with file:///C:/path/to/file. Note the three slashes after the colon.

What threw me off was that if you do

sheet.link(url, "sheetname", "", "", com.sun.star.sheet.SheetLinkMode.NORMAL)

which seems correct according to the API documentation, for an HTML-file the “sheetname” will not work even if that is one of the tables prompted when you do Sheet->Link to external data.

Probably this can only be used if you link another Calc-sheet, although I’m guessing here.

So three slashes in the URL and an empty string as the sheet name in Sheet.Link() works like I want it to.