[Solved] Move a picture from a sheet to another one

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
User avatar
Mr.Dandy
Posts: 463
Joined: Tue Dec 11, 2012 4:22 pm

[Solved] Move a picture from a sheet to another one

Post by Mr.Dandy »

Hello,
How can I do that?
CellAddress is a read only property.

Code: Select all

Sub Main
    MovePic("Image 1", "Sheet1", "Sheet2")
End sub

Sub MovePic(sName, sOldPlace, sNewPlace)
        oDoc = ThisComponent
        oSheetO = oDoc.Sheets.getByName(sOldPlace)    
        oSheetD = oDoc.Sheets.getByName(sNewPlace)    
        oPageO = oSheetO.getDrawPage    
        oPageD = oSheetD.getDrawPage    
        for i = 0 to oPageO.Count - 1
                    oImage = oPageO.getByIndex(i)
                    if oImage.Name = sName then exit for
        next
        oAddress = oImage.Anchor.getCellAddress()
        '??? not possible to just change oAddress.Sheet ???
End sub
Last edited by Mr.Dandy on Wed Oct 30, 2024 10:49 am, edited 2 times in total.
OpenOffice 4.1.12 - Windows 10
Bidouille
Volunteer
Posts: 662
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Move a picture from a sheet to another one

Post by Bidouille »

Code: Select all

Sub MovePic(sName, sOldPlace, sNewPlace)
	oDoc = ThisComponent
	oSheetO = oDoc.Sheets.getByName(sOldPlace)
	oSheetD = oDoc.Sheets.getByName(sNewPlace)
	oPageO = oSheetO.getDrawPage
	oPageD = oSheetD.getDrawPage
	for i = 0 to oPageO.Count - 1
		oOldImage = oPageO.getByIndex(i)
		if oOldImage.Name = sName then exit for
	next
	oNewImage = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
	with oNewImage
		.Name = sName
		.Size = oOldImage.Size
		.Position = oOldImage.Position
		.GraphicURL = oOldImage.GraphicURL
	end with
	oPageO.remove(oOldImage) 'first remove it
	oPageD.add(oNewImage)
	
End sub
Locked