Ok so I success but I don't understand
I see my picture but when it is copy from shape to graphic, it don't works. So I have work only on shape and it works.
- First question why copy shape to graphic then remove shape
- Second question, if I understand link is done by "oGraph.graphicurl = oShape.graphicurl" and So for me it don't works
Code working
Code: Select all
Sub InsertImage(ByRef oDoc As Object, ByRef oCurs As Object, sURL As Object, sParStyle As Object)
Dim serviceManager = CreateObject("com.sun.star.serviceManager")
Dim oShape
Dim oGraph
Dim oProvider
oShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
oDoc.getDrawPage().add(oShape)
oProvider = CreateUnoService("com.sun.star.graphic.GraphicProvider")
Dim oProps(0) As Object
oProps(0) = MakePropertyValue("URL", sURL)
REM Save the original size.
Dim oSize100thMM
Dim lHeight As Long
Dim lWidth As Long
oSize100thMM = RecommendGraphSize(oProvider.queryGraphicDescriptor(oProps))
If Not IsNothing(oSize100thMM) Then
lHeight = oSize100thMM.Height
lWidth = oSize100thMM.Width
End If
oShape.Graphic = oProvider.queryGraphic(oProps)
oGraph.graphicurl = oShape.graphicurl
oGraph.AnchorType = unoidl.com.sun.star.text.TextContentAnchorType.AS_CHARACTER
'oDoc.getDrawPage().remove(oShape)
If lHeight > 0 And lWidth > 0 Then
Dim oSize
oSize = oGraph.Size
oSize.Height = lHeight
oSize.Width = lWidth
oShape.Size = oSize
End If
' Set the paragraph style if it is in the document.
Dim oStyles
oStyles = oDoc.StyleFamilies.getByName("ParagraphStyles")
If oStyles.hasByName(sParStyle) Then
oCurs.ParaStyleName = sParStyle
End If
End Sub
code not working
Code: Select all
Sub InsertImage(ByRef oDoc As Object, ByRef oCurs As Object, sURL As Object, sParStyle As Object)
Dim serviceManager = CreateObject("com.sun.star.serviceManager")
Dim oShape
Dim oGraph
Dim oProvider
oShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
oDoc.getDrawPage().add(oShape)
oProvider = CreateUnoService("com.sun.star.graphic.GraphicProvider")
Dim oProps(0) As Object
oProps(0) = MakePropertyValue("URL", sURL)
REM Save the original size.
Dim oSize100thMM
Dim lHeight As Long
Dim lWidth As Long
oSize100thMM = RecommendGraphSize(oProvider.queryGraphicDescriptor(oProps))
If Not IsNothing(oSize100thMM) Then
lHeight = oSize100thMM.Height
lWidth = oSize100thMM.Width
End If
oShape.Graphic = oProvider.queryGraphic(oProps)
oGraph.graphicurl = oShape.graphicurl
oGraph.AnchorType = unoidl.com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oDoc.getDrawPage().remove(oShape)
If lHeight > 0 And lWidth > 0 Then
Dim oSize
oSize = oGraph.Size
oSize.Height = lHeight
oSize.Width = lWidth
oGraph.Size = oSize
End If
' Set the paragraph style if it is in the document.
Dim oStyles
oStyles = oDoc.StyleFamilies.getByName("ParagraphStyles")
If oStyles.hasByName(sParStyle) Then
oCurs.ParaStyleName = sParStyle
End If
End Sub