使用 word-interop 将图像添加到 word

adding image to word using word-interop

我正在尝试使用 hyper link 插入图像,下面是我的代码

            Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
            WordApp.Documents.Add();

            WordApp.Visible = true;
            Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;
            Microsoft.Office.Interop.Word.Range drange = doc.Range();
            Microsoft.Office.Interop.Word.InlineShape picture = 
            drange.InlineShapes.AddPicture("c:\logo.png", Type.Missing, Type.Missing, Type.Missing);

            // noew add the hyperlink to object of inlineshape
            drange.Hyperlinks.Add(picture, "http:\www.google.com", Type.Missing, Type.Missing, Type.Missing, Type.Missing);

但是当我 运行 项目时我得到一个错误 有谁知道为什么会这样或者我该如何解决它

Word 对象模型似乎不接受内联形状作为 Hyperlinks.Add 方法的锚点。尝试改用范围对象。您也可以尝试使用宏记录器来发现需要什么对象作为锚点。

Microsoft.Office.Interop.Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;                            
Microsoft.Office.Interop.Word.Application objApplication = Globals.ThisAddIn.Application;
Microsoft.Office.Interop.Word.Selection objSelection = objApplication.Selection;
Microsoft.Office.Interop.Word.Paragraphs p = objSelection.Paragraphs;
Microsoft.Office.Interop.Word.Range objRange = objSelection.Range;

Microsoft.Office.Interop.Word.InlineShape ils = objRange.InlineShapes.AddPicture(@"C:\..\image.PNG");
float scaledWidth = ils.Width;
float scaledHeight = ils.Height;