also would like to
- add a slide
- add a text on the slide
- add a picture on the slide
all from Calc BASIC macro
Thank you
also would like to
all from Calc BASIC macro
Thank you
Test this macro, change constants at the start to your usage:
Sub editPresentation 'duplicate the i-page in the presentation, and add text and picture to the duplicated one
const sUrl="d:\impress1.odp" 'path to your presentation
const i=0 'index of the page to be duplicate
const sImgUrl="d:\img1.png" 'path to the inserted image
dim oDoc as object, oPages as object, oPage as object, oShape as object, oImg as object, oSize as new com.sun.star.awt.Size
dim args(0) as new com.sun.star.beans.PropertyValue
args(0).Name="Hidden" : args(0).Value=false 'open the presentation in visible window
oDoc=StarDesktop.LoadComponentFromUrl(ConvertToUrl(sUrl), "_blank", 0, array())
rem add new page
oPages=oDoc.Drawpages 'pages in the presentation
oPage=oPages.getByIndex(i) 'page for duplication
oDoc.duplicate(oPage) 'duplicate the page
oPage=oPages.getByIndex(i+1) 'new page
rem add the text
oShape=oDoc.createInstance("com.sun.star.drawing.TextShape") 'text frame (more objects are described in the SDK documentation)
oPage.add(oShape) 'put text frame to the page
oShape.setPosition(createPoint(200,10000)) 'position
oShape.setSize(createSize(6000,1000)) 'size
oShape.setString("My new text")
'xray oShape - see more properties of the text frame
rem add the image
oImg=oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") 'image
oImg.graphicURL=ConvertToUrl(sImgUrl)
oImg.setPosition(createPoint(1000, 1000)) 'position
oPage.add(oImg)
wait 0.001 'maybe better is a little pause for get the width&height of the image reliably
oSize=oImg.Bitmap.Size100thMM
with oSize 'scale down the size of the image (LibreOffice inserts image like with 3/2 bigger DPI, so reduce size to 2/3 is for "original size" of inserted image)
.Width=CLng(2/3 * oSize.Width)
.Height=CLng(2/3 * oSize.Height)
end with
oImg.Size=oSize 'set "original size" to the inserted image
'xray oImg - see more properties of the image
' oDoc.store() 'save presentation
' oDoc.close(true) 'close presentation
End Sub
Function CreatePoint(ByVal x&, ByVal y&) as com.sun.star.awt.Point
Dim oPoint
oPoint=createUnoStruct( "com.sun.star.awt.Point" )
oPoint.X=x : oPoint.Y=y
CreatePoint=oPoint
End Function
Function CreateSize(ByVal x&, ByVal y&) as com.sun.star.awt.Size
Dim oSize
oSize=createUnoStruct( "com.sun.star.awt.Size" )
oSize.Width=x : oSize.Height=y
CreateSize=oSize
End Function
Great! Thank you very much!
On this site, answers are reserved for solutions. Please use the More link under your answer to make this a comment.