Page 1 of 1

Embed image with macro

Posted: Mon Sep 30, 2019 9:53 pm
by dedio
Hello everyone

How to embed image with macro?

I have this function

Code: Select all

Function FuncInsertImage(sPath As String, iWidth As Integer, iHeight As Integer, oBook As Object)
	Dim oSheet As Object
	Dim oImage As Object
	Dim sUrl As String
	Dim oTam As New com.sun.star.awt.Size

	sUrl = ConvertToURL(sPath)
	oSheet = oBook.getCurrentController.getActiveSheet.getDrawPage()
	oImage = oLibro.createInstance("com.sun.star.drawing.GraphicObjectShape")
	oImagen.GraphicURL = sUrl
	oSheet.add(oImage)
	oTam.Width = iWidth
	oTam.Height = iHeight
	oImage.setSize(oTam)
End Function
But just link the image
I need to embed it in the sheet

Re: Embed image with macro

Posted: Sat Aug 06, 2022 9:12 am
by ypvyas
There is error in above code in following two lines
oImage = oLibro.createInstance("com.sun.star.drawing.GraphicObjectShape")
oImagen.GraphicURL = sUrl

These lines be replaced with following two lines

oImage = oBook.createInstance("com.sun.star.drawing.GraphicObjectShape")
oImage.GraphicURL = sUrl

Re: Embed image with macro

Posted: Sat Aug 06, 2022 10:40 am
by Zizi64
__________________________________
OpenOffice: 5.2.7.2, on Debian
That version is LibreOffice. The API of the AOO and LO is a littlebit different by now.