Seite 1 von 1
Bild per Makro einfügen
Verfasst: Di, 18.04.2017 19:37
von Butch
Hallo! Ich bräuchte Folgendes:
Ein Makro, mit dem ich eine bestimmte Grafik (mit bestimmten Formateinstellungen) an belibieger Stelle einfügen kann.
(Die Grafik wäre an einer Stelle schon eingefügt, wie gewünsacht formatiert.)
Hätte jemand hier eine Idee, wie eine nicht zu umständliche Lösung aussehen könnte?
Das Hauptproblem ist wohl, wie die gesamten Daten des bereits eingefügten Bildes im Makro zu erfassen wären.
DiV.
Re: Bild per Makro einfügen
Verfasst: Mi, 19.04.2017 10:18
von Butch
Hallo! Bin ein Stück weiter gekommen. Wenn ich wüsste, wie die
Formatierungsoptionen für ein Bild im Makro zu
erfassen sind, hätte ich eine komplette Lösung. Bisher weiß ich im Wesentlichen nur, wie die Verankerung angegeben werden kann (siehe unten).
Fühlt sich dadurch vieleicht jemand hier inspiriert und kann mit dem entscheidenden Tipp helfen?
B.
Code: Alles auswählen
sub Test
'insert the image
dim oDoc as object, oDocFrame as object
dim oDrawPage as object, oDrawPageObj as object
dim dispatcher as object
oDoc = ThisComponent
oDocFrame = oDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FileName"
args1(0).Value = "file:///C:/Homepage/media/bild.png"
args1(1).Name = "FilterName"
args1(1).Value = "<All formats>"
args1(2).Name = "AsLink"
args1(2).Value = false
args1(3).Name = "Style"
args1(3).Value = ""
dispatcher.executeDispatch(oDocFrame, ".uno:InsertGraphic", "", 0, args1())
'operate on the last image inserted
oDrawPage = oDoc.DrawPage
oDrawPageObj = oDrawPage.getByIndex(oDrawPage.Count - 1)
oDrawPageObj.AnchorType = 1 ' 0 par, 1 as char, 2 page, 4 char
'oDrawPageObj.Opaque = False ' in Background
'oDrawPageObj.Surround = 1 ' this and next seem to give Wrap Through
'oDrawPageObj.TextWrap = 1
' nienberg: https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=25505
end sub
Re: Bild per Makro einfügen
Verfasst: Mi, 19.04.2017 12:42
von Butch
@WiM:
Danke! Ja, bin gerade dabei, alle solche Hinweise zu durchforsten, komme abere nur langsam voran.
Aus verschiedenen Quellen habe ich mir auch einen anderen Ansatz erarbeitet (siehe unten).
B.
Code: Alles auswählen
Sub Test
Dim oDoc As Object
Dim sURL As String
Dim oViewCursor
Dim oGraph
Dim oText
Dim Var
oDoc = ThisComponent
sURL = "file:///C:/Homepage/media/bild.png"
oText = oDoc.getText()
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
With oGraph
.GraphicURL = sURL
.AnchorType = 1 ' 0 at par, 1 as char, 2 at page, 4 at char (*)
.Width = 550 ' in 1/1000 cm
.Height = 800
End With
oText.insertTextContent(oViewCursor, oGraph, False)
' (*) 1 or : com.sun.star.text.TextContentAnchorType.AS_CHARACTER
' other anchor types: AT_PARAGRAPH, AT_PAGE, AT_CHARACTER, AT_FRAME
' .HoriOrient = 1 ' 1 right, 2 center ...
End Sub
Re: Bild per Makro einfügen
Verfasst: Do, 20.04.2017 14:34
von Butch
Trara!
Mit viel Mühe habe ich schließlich eine fast komplette Lösung erarbeitet.
B.
Code: Alles auswählen
Sub BildEinfuegen
Dim oDoc As Object
Dim oViewCursor
Dim oGraph
Dim oText
Dim Var
oDoc = ThisComponent
oText = oDoc.getText()
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
With oGraph
.GraphicURL = "file:///C:/Homepage/media/bild.png"
.AnchorType = 3 ' 1 as char, 2 to page, 3 to para, 4 to char (*)
.Width = 550 ' in 1/1000 cm
.Height = 700
.LeftMargin = 0
.RightMargin = 200
.TopMargin = 0
.BottomMargin = 50
.HoriOrient = 0 ' 1 2 3 = right center left, 0 from ... (1)
.VertOrient = 1 ' 1 2 3 = top center bottom, 0 from ... (2)
.HoriOrientRelation = 1 ' (3)
.VertOrientRelation = 1 ' (4)
.HoriOrientPosition = 10 ' by ...
.VertOrientPosition = 0
.Surround = 2 ' 0 none 1 through 2 parallel 3 optimal 4 before 5 after
End With
oText.insertTextContent(oViewCursor, oGraph, False)
' (1)
' with to page: to entire page
' with to para: to para area
' with to char: to para area
' with as char: of course no influence (is a 'character'!)
' (2)
' with to page: to entire page
' with to para: to margin
' with to char: to margin
' !!! with as char: 1 2 3 to base line, 4 5 6 to char, 7 8 9 to row (!!!!!!)
' (3)
' with to page: 1+2 pag te ar, 3 le pag bo, 4 ri pag bo, 5 le pag bo, 6 ri pag bo, 7 ent pag
' with to para: 1 par te ar, 2 pag te ar, 3 le pag bo, 4 ri pag bo, 5 le par bo, 6 ri par bo, 7 ent pa
' with to char: 1 par te ar, 2 char, 3 le pag bo, 4 ri pag bo, 5 le par bo, 6 ri par bo, 7 ent pag, 8 pag te ar, 9 char
' with as char: of course no influence!
' (4)
' with to page: 1+2 pag te ar, 34567 ent pag
' with to para: 1 par te ar, 2 pag te ar, 3+4+5+6 mar, 7 ent pa
' with to char: 1 par te ar, 2 char, 3+4+5+6 mar, 7 ent pag, 8 pag te ar, 9 li of t
' with as char: no influence, setting is done via VertOrient (!!!!!!)
' Bugs (?):
' with to page: 2 pag te ar, but placed vert rel to entire page
' with to page: 9 pag te ar, but placed vert&hor rel to entire page
' (*) Alternativ:
' .AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
' (other types: .AT_PARAGRAPH, .AT_PAGE, .AT_FRAME, .AT_CHARACTER).
' https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/Shape.html
End Sub