我是用这句代码插入的图片:
//插入图片
object Anchor = myWord.Application.Selection.Range;
bp.Save(bmpPath);
myDoc.InlineShapes.AddPicture(bmpPath, ref Nothing, ref Nothing, ref Anchor);
Anchor是当前行,我就是想把Anchor变成指定字符串的位置。
或者大神有其他方法也希望能够告诉我。
看你怎么指定了,你首先可以定义你指定的位置为选区。
myWord.Application.ActiveDocument.Find(...).Select()
http://tobetobe.blog.51cto.com/1392243/353684
这个网址可以解决你的问题
object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
/* wdReplaceAll - 替换找到的所有项。
* wdReplaceNone - 不替换找到的任何项。
* wdReplaceOne - 替换找到的第一项。
*/
Object LinkToFile = false;
object SaveWithDocument = true;
object dummy = System.Reflection.Missing.Value;
object count = 1;
object Unit = Microsoft.Office.Interop.Word.WdUnits.wdCharacter;
thisApplication.Selection.MoveRight(ref Unit, ref count, ref dummy);
thisApplication.Selection.Find.ClearFormatting();//移除Find的搜索文本和段落格式设置
//查找文本内容
thisApplication.Selection.Find.Text = "文本内容";
thisApplication.Selection.Find.Execute(ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
object Anchor = thisApplication.Selection.Range;
//插入图片
Microsoft.Office.Interop.Word.InlineShape shape = thisApplication.Selection.InlineShapes.AddPicture(“为图片地址”, ref LinkToFile, ref SaveWithDocument, ref Anchor);
thisApplication.Selection.Find.Replacement.ClearFormatting();
//清空文本
thisApplication.Selection.Find.Replacement.Text = "";
thisApplication.Selection.Find.Execute(ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref replaceAll, ref nothing, ref nothing, ref nothing, ref nothing);