C# - Microsoft word interop查找文本替换为图片

时间:2015-03-19 10:32:07

标签: c# image text replace office-interop

如何在word文档中找到文本并用图片替换文本?我知道如何用文本替换文本,但是无论如何用文字替换文本?

1 个答案:

答案 0 :(得分:1)

如果您要替换的文字有一个有效的Word.Range对象,则可以使用InlineShapes.AddPicture()

例如:

// Get the Range for the text you want to replace, which you claim to be able to do already.
Word.Range selectedText = GetTextToReplace();

// Clear the existing text, otherwise the image will just be appended after the text.
selectedText.Text = "";

// Insert the image.
selecetdText.InlineShapes.AddPicture(imagePath, Type.Missing, true, Type.Missing);