Word VSTO-填充形状在Word 2010和Word 2013中不起作用? [英] Word VSTO - Filling a shape does not work in Word 2010 and Word 2013?

查看:159
本文介绍了Word VSTO-填充形状在Word 2010和Word 2013中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下VB.NET(VSTO)代码在MS-Word中添加形状,

I use the following VB.NET (VSTO) code to add a shape in MS-Word,

Dim app As Word.Application = Globals.ThisAddIn.Application
Dim doc As Word.Document = app.ActiveDocument
Dim left As Single = CSng(Convert.ToDouble(app.Selection.Information(Word.WdInformation.wdHorizontalPositionRelativeToPage)))
Dim top As Single = CSng(Convert.ToDouble(app.Selection.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)))
Dim shape As Word.Shape = doc.Shapes.AddShape(1, left, top, 225.1F, 224.5F)

shape.Fill.BackColor.RGB = ColorTranslator.ToOle(Color.Transparent)
shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
shape.Fill.Transparency = 0.0F
shape.Line.Transparency = 0.0F
shape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
shape.Fill.UserPicture("C:\Newfolder\App1.jpg")

此代码的作用是,在光标处添加一个矩形形状,使其透明(包括背景和线条),并添加(填充)图像.

What this code does is, it adds a rectangle shape at cursor point, makes it transparent (both background and line) and adds (fills) an image.

这在 Word 2007 中可以正常工作.但是在 Word 2010 Word 2013 上存在问题.它在光标处添加矩形形状并使其透明.但是它不会填充图像.

This works fine in Word 2007. But on Word 2010 and Word 2013 there is an issue. It adds the rectangle shape at cursor point and makes it transparent. But it does not fill the image.

shape.Fill.UserPicture("C:\Newfolder\App1.jpg")

上面的代码行在Word 2010和Word 2013中不起作用.其他部分工作正常.如何在Word 2010和2013中修改代码以将图像填充为矩形形状?

The above line of code does not work in Word 2010 and Word 2013. Other parts works fine. How to modify the code to fill the image in the rectangle shape in Word 2010 and 2013?

推荐答案

代替shape.Fill.UserPicture("C:\Newfolder\App1.jpg")试试

    Word.Range range = shape1.TextFrame.TextRange;
    range.InlineShapes.AddPicture(@"C:\Newfolder\App1.jpg", false, true, Type.Missing);

这篇关于Word VSTO-填充形状在Word 2010和Word 2013中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆