Macro, copy a shape and paste it in another sheet

Creating a macro - Writing a Script - Using the API

Macro, copy a shape and paste it in another sheet

Postby merouaneb » Thu May 23, 2019 3:01 am

Hi, Community
I'm a new user in Open office, and i'm searching for resolving a problem that is structure like this:
I've a bitmap and from a sheet 1, i want to copy it and paste it in another sheet, and resizing to fit a 5 cells.
please help,me.
OpenOffice 4.1 on Windows 10
merouaneb
 
Posts: 2
Joined: Thu May 23, 2019 2:17 am

Re: Macro, copy a shape and paste it in another sheet

Postby Lupp » Thu May 23, 2019 3:19 pm

Why do you think you need a "macro"? Wherever possible do it without.

There are lots of specifics you need to consider for the task.
I will only post a raw specialised example. It assumes there is exactly one shape on the first sheet and NONE so far on the second.
It's complicated otherwise to identify the shapes to work on.
Concerning the size I don't worry about cell areas, but only demonstrate in principle how to set a shape's size to chosen values.
Code: Select all   Expand viewCollapse view
Sub copyFirstShapeFromShee1ToSheet2CellD5()
doc0   = ThisComponent
cc     = doc0.CurrentController
dpr    = cc.Frame
dh     = createUnoService("com.sun.star.frame.DispatchHelper")
sheet0 = doc0.Sheets(0)
sheet1 = doc0.Sheets(1)
target = sheet1.GetCellRangeByName("D5")
dp0    = sheet0.DrawPage
dp1    = sheet1.DrawPage
shape0 = dp0(0)
cc.select(shape0)
dh.executeDispatch(dpr, ".uno:Copy",  "", 0, Array())
cc.select(target)
dh.executeDispatch(dpr, ".uno:Paste", "", 0, Array())
shape1 = dp1(0)
sz = shape1.Size
With sz
.Height = .Height/2
.Width = .Width/2
End With
shape1.setSize(sz)
shape1.Anchor = target
End Sub


See alao attachment.
Attachments
shapeCopyDemo.ods
(96.45 KiB) Downloaded 87 times
On Windows 10: LibreOffice 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Macro, copy a shape and paste it in another sheet

Postby merouaneb » Thu May 23, 2019 11:38 pm

Hi,
Thank's for responding Lupp, Your solution work fine :bravo: but in my case when i try to modify the code to be suitable to my case just it doesnt work like i want.!!!!! :crazy:
This is a portion of my code, it's a function:
Code: Select all   Expand viewCollapse view
Function flip_past(ranges,Calli)
doc   = ThisComponent
cc     = doc.CurrentController
dpr    = cc.Frame
dh     = createUnoService("com.sun.star.frame.DispatchHelper")
'sheet0 = doc.getSheets
'sheet1 = doc.sheets(5)
target = ThisComponent.getSheets.getByName("Doc").getCellRangeByName(ranges)
dp     = ThisComponent.getSheets.getByName("Legende").DrawPage
dp1    = ThisComponent.getSheets.getByName("Doc").DrawPage
shape = dp(Calli)
nom = ActiveWindow.Selection.ShapeRange.Name 'TextFrame.TextRange.BoundWidth
MsgBox (nom)

cc.select(shape)
dh.executeDispatch(dpr, ".uno:Copy",  "", 0, Array())
cc.select(target)
dh.executeDispatch(dpr, ".uno:Paste", "", 0, Array())
shape1 = dp1(Calli)
sz = shape1.Size

With sz
.Height = target.size.Height
.Width = target.size.Width
End With
shape1.setSize(sz)
shape1.Anchor = target   

End Function


Where Calli is the name of the shape, and ranges is a range from L12:L50
best regards, Yours.
OpenOffice 4.1 on Windows 10
merouaneb
 
Posts: 2
Joined: Thu May 23, 2019 2:17 am

Re: Macro, copy a shape and paste it in another sheet

Postby Lupp » Fri May 24, 2019 12:24 am

Sorry. I shouldn't have started this. Giving the above example I mainly intended to show how complicated even the simplest task of the kind under facilitating assumptions to the greatest extent would be.

I told you it's complicated and it is. This is not only concerning the identification of shapes. If you actually urgntly need to do things of the kind by macros, you need to learn to design them from the beginning. You need to understand some concepts of the API - and many details. Start studying the guide and the famous texts by Andrew Pitonyak - and be prepared to experience that many things were changed since, and that finding documentation is difficult.
On Windows 10: LibreOffice 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests