以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- word报表图片添加 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=169197) |
-- 作者:qaz17909 -- 发布时间:2021/6/6 20:59:00 -- word报表图片添加 见实例,想在盖章的位置加上一个印章,但是实例加上图片后,后面的日期往下移了,另外就是采用替换的方法,“盖章”两个字也没了。希望能够实现图片浮于文字上方,并且保留“盖章”两个字。效果如下图所示: |
-- 作者:有点蓝 -- 发布时间:2021/6/6 21:34:00 -- http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=126389 http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=159575&skin=0
|
-- 作者:qaz17909 -- 发布时间:2021/6/7 9:23:00 -- 可以添加图片,但是还有个地方不够完美。现在是通过绝对定位插入图片,但是如果盖章的位置随着文档的长短有上下变动的时候,会出现图片位置与盖章位置的偏离。有没有办法,通过“盖章”这个文字来定位。 |
-- 作者:有点蓝 -- 发布时间:2021/6/7 9:25:00 -- 2楼第二个链接就有这个用法说明 |
-- 作者:qaz17909 -- 发布时间:2021/6/7 9:58:00 -- 我看二楼最后也是通过决定定位实现的啊,蓝老师可否帮我改下实例,谢谢! |
-- 作者:有点蓝 -- 发布时间:2021/6/7 9:59:00 -- http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=126389 |
-- 作者:qaz17909 -- 发布时间:2021/6/7 10:24:00 -- 蓝版,二楼的代码我都试过了,二楼第二个链接的方法是可以用字符替换图片的方式找到具体的位置,但是却无法实现图片浮于文字上方,后来我看那个同行也是通过具体定位来插入图片的。两者想同时兼具,在字符的位置插入图片并且图片浮于文字上方好像没有最终实现。 |
-- 作者:有点蓝 -- 发布时间:2021/6/7 10:46:00 -- 学会结合使用呀 Set sha = Selection.InlineShapes.AddPicture(filename:=projectpath & "images\\张杰.png", linktofile:=False, savewithdocument:=True).ConvertToShape \'插入图形 With sha .WrapFormat.Type = wdWrapFront \'设置文字环绕方式,wdwrapfront置于文字上方,wdwrapbehind置于文字下方,wdwrapthrough四周环绕…… .LockAspectRatio = msoCTrue \'锁定纵横比 .Height = CentimetersToPoints(2) \'缩小为原来的20% .RelativeHorizontalPosition = wdRelativeHorizontalPositionRightMarginArea \'相对于右边距 .Left = -.Width \'取图片宽度的负数 .RelativeVerticalPosition = wdRelativeVerticalPositionBottomMarginArea \'相对于下边距 .Top = -.Height \'取图片高度的负数 End With |
-- 作者:qaz17909 -- 发布时间:2021/6/7 11:38:00 -- 我写法上是不是有什么不对,提示出错 Dim fl As String = ProjectPath & "test.docx" Dim fl1 As String = ProjectPath & "test1.docx" FileSys.CopyFile(fl,fl1,True) Dim img As String = ProjectPath & "印章.png" Dim app As New MSWord.Application try Dim doc = app.Documents.Open(fl1) app.Selection.Find.Text = "盖章" app.Selection.Find.Execute Dim pic = app.Selection.InlineShapes.AddPicture(img, False, True) With pic .WrapFormat.Type = wdWrapFront .LockAspectRatio = msoCTrue \'锁定纵横比 .Height = CentimetersToPoints(2) \'缩小为原来的20% .RelativeHorizontalPosition = wdRelativeHorizontalPositionRightMarginArea \'相对于右边距 .Left = -.Width \'取图片宽度的负数 .RelativeVerticalPosition = wdRelativeVerticalPositionBottomMarginArea \'相对于下边距 .Top = -.Height \'取图片高度的负数 .LockAspectRatio = True .Height = 100 End With Doc.SaveAs(Filename:= fl1) catch ex As exception msgbox(ex.message) app.Quit finally End try Dim Proc As New Process Proc.File = fl1 Proc.Start() |
-- 作者:有点蓝 -- 发布时间:2021/6/7 11:55:00 -- Dim pic = app.Selection.InlineShapes.AddPicture(filename:=img, linktofile:=False, savewithdocument:=True).ConvertToShape \'插入图形 With pic .WrapFormat.Type = MSWord.WdWrapTypeMerged.wdWrapFront .Height = app.CentimetersToPoints(2) \'缩小为原来的20% .RelativeHorizontalPosition = MSWord.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionRightMarginArea \'相对于右边距 .Left = -.Width \'取图片宽度的负数 .RelativeVerticalPosition = MSWord.WdRelativeVerticalPosition.wdRelativeVerticalPositionBottomMarginArea \'相对于下边距 .Top = -.Height \'取图片高度的负数 .LockAspectRatio = True .Height = 100 End With
|