Calc Macros - Inserting image as linked image

A continuation of this thread

Code like this works fine for me

Folder = "C:\Users\fjcc\Desktop\"

imagen = "W21_0.TIF"
ImagenURL = convertToURL(Folder & imagen)
oImagen_obj = ThisComponent.createInstance("com.sun.star.drawing.GraphicObjectShape")

oImagen_obj.GraphicURL = ImagenURL
oSize = oImagen_obj.Size
oSize.Height = 3000
oSize.Width = 3000
oImagen_obj.Size = oSize
oPos = oImagen_obj.Position
oPos.X = 2000
oPos.Y = 3000
oImagen_obj.Position = oPos

currentIndex = ThisComponent.CurrentController.ActiveSheet.RangeAddress.Sheet
oDP = ThisComponent.DrawPages.getByIndex(currentIndex)
oDP.add(oImagen_obj)

There is only one problem. I want these images to be inserted into spreedsheet as linked images - so ods file wont increase in filesize too much (I’m gonna keep source images in right directory no worries here).

I’ve read documentation about GraphicObjectShape
https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1drawing_1_1GraphicObjectShape.html
and found this GraphicStreamURL, so I’ve replaced


oImagen_obj.GraphicURL = ImagenURL

with


oImagen_obj.GraphicStreamURL = ImagenURL

My expectations were that this will place image in spreedsheet with linked image. It indeed creates object but with missing image:


Anyone knows how to handle this? Do I need to modify image path somehow? Or do I need to do this in completely different way?

Are you trying to build a database with pictures for each record? LibreOffice comes with a database component.

No, I’ve been looking at database approach and I didn’t liked that way. I want to be able to spawn image in spreedsheet with chosen size and position by clicking a button.

Good luck. Even if you store all the data in a spreadsheet, Base can spawn all the images by simply opening a report without a single line of code.
https://download1500.mediafire.com/j8204ssav6sgm19bIF_RU6QxyLVA6__T_-NqoClMIftgJyn9qlBQh_NnATdI3JOKzTXpLeatVxVxpBMMT8wybSw7Rt6E8tbwYrvP5sE7w5cAH1raAkid-NBkbznA1xRnFSUmpWcIKY6VhI_wmr2mo3Ha7Se0zrTIYfXatTGa708w/bxmgmowupp0wsw1/PicsDB.zip