在 Word 文档中使用图像查找和替换文本 [英] Find and replace text with an image in Word document
问题描述
我已经想出了如何替换文档中的单词,因为使用 find 对象相当容易.现在我正在努力用整个 Word 文档中的实际徽标图像替换logo"这个词.
I have figured out how to replace words in documents as this is fairly easy using the find object. Now I am struggling with replacing the word "logo" with an actual logo image throughout a word document.
我想我可以遍历文档中的每个范围并说如果在该范围中找到logo这个词,我可以添加一张图片:
I figured I can loop through each Range in the document and say that if the word logo is found in the range, I can add a picture doing:
foreach (Range rngStory in doc.StoryRanges)
{
rngStory.InlineShapes.AddPicture(filename);
}
问题是这会将图片添加到范围的顶部,而不是文本徽标的确切位置.
The problem is that this will add the picture to the top of the range and not exactly where the text logo is.
有没有人有好的解决方案?
Does anyone have a good solution for doing this?
推荐答案
查看可选的 Range 参数
See the optional Range parameter
范围
可选对象.图片将被放置的位置在文中.如果范围未折叠,则图片将替换范围;否则,插入图片.如果这个论点是省略,图片自动放置.
Optional Object. The location where the picture will be placed in the text. If the range isn't collapsed, the picture replaces the range; otherwise, the picture is inserted. If this argument is omitted, the picture is placed automatically.
所以我会说您查询您拥有 logo 标签的当前位置,并将其用作范围值.
So I would say you query for the current position where you have you logo tag, and use that as the Range value.
这篇关于在 Word 文档中使用图像查找和替换文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!