Eviliy
2015-06-28 08:33
采纳率: 33.3%
浏览 3.9k

C# .NET,操作WORD在指定字符串位置插入图片。

我是用这句代码插入的图片:

  //插入图片
object Anchor = myWord.Application.Selection.Range;
bp.Save(bmpPath);
myDoc.InlineShapes.AddPicture(bmpPath, ref Nothing, ref Nothing, ref Anchor);

Anchor是当前行,我就是想把Anchor变成指定字符串的位置。
或者大神有其他方法也希望能够告诉我。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • threenewbee 2015-06-28 14:58

    看你怎么指定了,你首先可以定义你指定的位置为选区。
    myWord.Application.ActiveDocument.Find(...).Select()

    打赏 评论
  • csdnXiaoF 2015-06-29 05:32

    http://tobetobe.blog.51cto.com/1392243/353684
    这个网址可以解决你的问题

    打赏 评论
  • MMLLCSDN 2015-07-02 07:34
                    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);
    
    打赏 评论

相关推荐 更多相似问题