老师,下面是印章跟随代码,印章位置不固定,帮忙看一下代码,现在出现印章不能替换“盖章”两个字问题
Dim fl As String = ProjectPath & "Attachments\test2移动.doc"
Dim fl1 As String = ProjectPath & "Reports\用印文件\" & format(Date.now, "yyyy-MM-dd") & "\" & "test2(已用印).doc" ''
FileSys.CopyFile(fl, fl1, True)
Dim img As String = ProjectPath & "Attachments\电子印章2.png"
Dim app As New MSWord.Application
Try
Dim doc As Object = app.Documents.Open(fl)
Dim item = "【盖章】" '被替换的字符
Dim sel = app.Selection
sel.Find.ClearFormatting
With sel.Find
.Text = item
.Replacement.Text = ""
.Forward = True
.Wrap = MSWord.WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
sel.Find.Execute
Dim pic As MSWord.InlineShape = sel.InlineShapes.AddPicture(img)
pic.Height = 100 '图片高
pic.Width = 100 '图片宽
Dim p2 = pic.ConvertToShape
p2.WrapFormat.Type = MSWord.WdWrapType.wdWrapBehind
With p2
.Left = .Left - .Width / 0.75 '向左偏移1个图大小
.Top = .Top + .Height / 2 '向上偏移三分之一图大小,正确
End With
Doc.SaveAs(Filename:= fl1)
Catch ex As exception
msgbox(ex.message)
app.Quit
Finally
End Try