Bonjour,
J'ai bien regardé d'autres sujets sur ce forum et je n'ai toujours pas trouvé comment faire ce que je veux.
En m'inspirant notamment de cet exemple et de l'outil pour enregistrer "manuellement" des macros, j'ai écrit le code suivant :
Code : Tout sélectionner
OPTION EXPLICIT
Sub CopierColler
Dim oDoc As Object, oSheet As Object, oDrawPage As Object
Dim document As Object
Dim dispatcher As Object
Dim args2(0) As New com.sun.star.beans.PropertyValue
oDoc = thisComponent
oSheet = oDoc.sheets.getByName("Feuille1")
oDrawPage = oSheet.DrawPage("ImgOooriginale")
thiscomponent.currentcontroller.select(oDrawPage) 'Sélection de l'image
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array()) 'Copie de l'image
'Définition de la cellule de destination
args2(0).Name = "ToPoint"
args2(0).Value = "$F$30"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2()) 'Sélection de la cellule
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array()) 'Collage de l'image
End SubJ'ai aussi pensé à une solution de ce type
Code : Tout sélectionner
OPTION EXPLICIT
Sub CopierColler2
Dim oDoc As Object
Dim oDrawPage As Object
Dim oImage As Object
Dim i As Integer
oDoc = ThisComponent
oDrawPage = oDoc.getDrawPages().getByIndex(0)
For i=0 To oDrawPage.count-1
oImage = oDrawPage.getbyindex(i)
If oImage.Name = "ImgOooriginale" Then Exit For
Next i
Dim oGP As Object, oDP As Object
Dim monGraphique As Object
Dim oMP(0) As New com.sun.star.beans.PropertyValue
oGP = createUnoservice("com.sun.star.graphic.GraphicProvider")
oMP(0).Name = "URL"
oMP(0).value = oImage.GraphicURL
monGraphique = oGP.queryGraphic(oMP)
' Créer un nouvel objet DrawPage...
' oDP = oDoc.sheets.getByname("Feuille1").GetDrawpage(i)
' oDP(i).graphic = monGraphique
End SubIl me manque encore un truc pour avancer là aussi.
Auriez-vous une idée ou un lien vers un sujet que je n'aurai pas trouvé et qui pourrait me débloquer svp ?
Si jamais : (désolé pour l'image, j'avais que ça de léger en stock..)
[Edit] J'essaye encore d'une autre façon :
Code : Tout sélectionner
Sub CopyPaste3
Dim document as object
Dim oDoc As Object
Dim oDrawPage As Object
Dim oImage As Object
Dim i As Integer
Dim Img as string
document = ThisComponent.CurrentController.Frame
oDoc = ThisComponent
oDrawPage = oDoc.getDrawPages().getByIndex(0)
For i=0 To oDrawPage.count-1
oImage = oDrawPage.getbyindex(i)
If oImage.Name = "ImgOooriginale" Then Exit For
Next i
Img = oImage.GraphicURL
dim dispatcher as object
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$F$30"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FileName"
args2(0).Value = Img
args2(1).Name = "FilterName"
args2(1).Value = "JPEG - Joint Photographic Experts Group"
args2(2).Name = "AsLink"
args2(2).Value = false
dispatcher.executeDispatch(document, ".uno:InsertGraphic", "", 0, args2())
End Sub

