Re: Import von 400 Barcode Seriennummer
Verfasst: Sa, 11.10.2014 23:51
Du möchtest 400 verschiedene Vorlagen (aus einer "Master"-Vorlage) mit 400 verschiedenen Bildern erzeugen... oder wie soll ich die Frage verstehen?
deutsches Forum rund um Apache OpenOffice und LibreOffice
https://de.openoffice.info/
Code: Alles auswählen
Sub AddProportionalGraphic
' 2014-10-12
' nach Beispielcode Nr. 269 von Andrew Pitonyak
' Name der Dokumentvorlage
url = ConvertToUrl("/home/USER/Documents/vorlagen/Tagesreport.ott")
' Name des einzufügenden Bildes
bild = ConvertToUrl("/home/USER/Documents/Bilder/FoE/openSuse-1.jpg")
Dim oDoc 'Newly created Impress document
Dim oDrawPage 'The draw page that will contain the graphic image
Dim oGraph 'The created graphic image
REM Create an Impress presentation document!
oDoc = StarDesktop.loadComponentFromURL( _
url , "_default", 0, Array())
REM Insert a second draw page if desired,
REM leaving the first draw page untouched!
REM Could use the property DrawPages
REM oDrawPage = oDoc.DrawPages.insertNewByIndex(1)
REM oDrawPage = oDoc.getDrawPages().insertNewByIndex(1)
REM In this case, simply use the first draw page!
oDrawPage = oDoc.getDrawPage()
REM Create a graphics object that can be inserted into the document
oGraph = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
REM Set the URL of the image so that it can be added to the document
oGraph.GraphicURL = bild
oDrawPage.add(oGraph)
REM If I stop here, there will be a very small graphic image in the
REM upper-left corner of the document. This is pretty much useless.
REM Although I could simply size the graphic to the same size as the bitmap
REM size, I choose instead to size this so that it is as large as possible
REM without changing the aspect ratio.
REM Determine the ratio of the height to the width for the image and
REM also for the draw page.
Dim oNewSize As New com.sun.star.awt.Size 'New Image size
Dim oBitmapSize As New com.sun.star.awt.Size 'Bitmap size
Dim dImageRatio As Double 'Ratio of the height to width
Dim dPageRatio As Double 'Ratio of the height to width
' oBitmapSize = oGraph.GraphicObjectFillBitmap.GetSize
' dImageRatio = CDbl(oBitmapSize.Height) / CDbl(oBitmapSize.Width)
' dPageRatio = CDbl(oDrawPage.Height) / CDbl(oDrawPage.Width)
REM Compare the ratios to see which is wider, relatively speaking
' If dPageRatio > dImageRatio Then
' oNewSize.Width = oDrawPage.Width
' oNewSize.Height = CLng(CDbl(oDrawPage.Width) * dImageRatio)
' Else
' oNewSize.Width = CLng(CDbl(oDrawPage.Height) / dImageRatio)
' oNewSize.Height = oDrawPage.Height
' End If
oNewSize.Width = 1500
oNewSize.Height = 2000
REM Center the image on the Impress page!
Dim oPosition as new com.sun.star.awt.Point
' oPosition.X = (oDrawPage.Width - oNewSize.Width)/2
' oPosition.Y = (oDrawPage.Height - oNewSize.Height)/2
oPosition.X = 4000
oPosition.Y = 2000
oGraph.SetSize(oNewSize)
oGraph.SetPosition(oPosition)
End Sub