【发布时间】:2015-05-22 10:14:03
【问题描述】:
如何在word文档中查找文字并将文字替换为图片?我知道怎么用文字代替文字,但是有没有用图片代替文字呢?
【问题讨论】:
-
用文本替换文本的代码是什么?
标签: c# image text replace office-interop
如何在word文档中查找文字并将文字替换为图片?我知道怎么用文字代替文字,但是有没有用图片代替文字呢?
【问题讨论】:
标签: c# image text replace office-interop
如果您有一个有效的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);
【讨论】: