如何使用Interop C#或VB替换Word 2013+中Picture Content Control中的现有图片

问题描述 投票:0回答:1

我正在使用Word2013。我转到“开发人员”选项卡,向我的文档添加“图片内容控件”。将其标题设置为“徽标”。然后,单击控件并设置默认图像。

我的问题是如何使用Word Interop(请不要使用OpenXML)将默认图像替换为任何其他图像,语言可以是C#或VB都没有关系。

using Microsoft.Office.Interop.Word;

ContentControls controls = d.SelectContentControlsByTitle("logo");
foreach (ContentControl c in controls)
{
    if (c.Type == WdContentControlType.wdContentControlPicture)
    {                        
        // ContentControl of Interop.Word doesn't have Image property
        // Couldn't cast the Microsoft.Office.Tools.Word.PictureContentControl either
    }
}
c# ms-word interop
1个回答
0
投票

您可以这样替换图片,

ContentControls controls = doc.SelectContentControlsByTitle("logo");

foreach (ContentControl contentControl in controls)
{
    var cc = contentControl.Range.InlineShapes.AddPicture("imageLocation");
}
© www.soinside.com 2019 - 2024. All rights reserved.