Embed image with macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
dedio
Posts: 1
Joined: Mon Sep 30, 2019 9:21 pm

Embed image with macro

Post 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
OpenOffice: 5.2.7.2, on Debian
ypvyas
Posts: 1
Joined: Sat Aug 06, 2022 9:08 am

Re: Embed image with macro

Post 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
Open Office 4.1.13
Windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Embed image with macro

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply