我正在尝试在单词doc的右上角添加徽标,但我无法。 我试过Mr.Goggle,但我找不到答案。 请我绝望。救命!
oPara(1) = oDoc.Content.Paragraphs.Add
oPara(1).Range.Text = "Text"
oPara(1).Range.InlineShapes.AddPicture(FileName:="C:\logo.png")
oPara(1).Range.InlineShapes.Item(1).ScaleWidth = 20
oPara(1).Range.InlineShapes.Item(1).ScaleHeight = 20
oPara(1).Range.InlineShapes.Item(1) ?? <---
谢谢大家!
答案 0 :(得分:1)
尝试将其添加为Shape而不是InlineShape。这为您提供了一些控制其定位的属性,您可以通过设置Shape的WrapFormat.Type来获得内联形状的效果:
Dim logoFilepath As String = "C:\logo.png"
Dim sampleText As String = ""
For i As Integer = 0 To 200
sampleText &= "sample text "
Next
Dim oApp As Word.Application = New Word.Application
oApp.Visible = True
Dim oDoc As Word.Document = oApp.Documents.Add
Dim oPara As Word.Paragraph = oDoc.Content.Paragraphs.Add
oPara.Range.Text = sampleText
Dim oShape As Word.Shape = oDoc.Shapes.AddPicture(logoFilepath, False, True)
With oShape
.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin
.Left = Word.WdShapePosition.wdShapeRight
.WrapFormat.Type = Word.WdWrapType.wdWrapSquare 'wdWrapTopBottom if you want the text below the logo
End With
答案 1 :(得分:0)
好的伙计们,感谢所有的帮助,我设法让自己成为一个解决方案,提供你给我的所有建议。所以我做了一个新的段落并将对齐设置为正确的:) 像这样:
oPara(0) = oDoc.Content.Paragraphs.Add
oPara(0).Range.InlineShapes.AddPicture(FileName:="C:\Users\"user"\"folder"\logo.png")
oPara(0).Range.InlineShapes.Item(1).ScaleWidth = 20
oPara(0).Range.InlineShapes.Item(1).ScaleHeight = 20
oPara(0).Format.SpaceAfter = 0
oPara(0).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
oPara(1) = oDoc.Content.Paragraphs.Add
oPara(1).Range.Text = "Text"
oPara(1).Range.Font.Bold = True
oPara(1).Range.Font.Color = RGB(0, 85, 81)
oPara(1).Range.Font.Size = 16
oPara(1).Format.SpaceAfter = 0
oPara(1).Range.InsertParagraphAfter()