c# word 插入图片问题

情景描述:

  在之前文本框中加标签,代码直接addPicture出现了意外。不起作用,怀疑是文档模板的问题,因为生成的PDF和word格式总时不时有差异,左右捣鼓下,更换文本框,更换图片形式,形状形式,放成最大,布局格式调整,绝对位置调整,都不行。

原理描述:

  在文档行不通的时候,或者可以把文档模板重新设计抑或文档模板中直接添加上,判断情况删去。无疑都是很麻烦。这个时候决定换种插入图片的方法,行得通。

代码附上:

//查找书签
                        object bookMark = "shenheName";
                        oDoc.Bookmarks.get_Item(ref bookMark).Select();
                        //设置图片位置
                        oWord.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustifyMed;
                        //在书签的位置添加图片
                        //定义该插入图片是否为外部链接
                        object linkToFile = true;
                        //定义插入图片是否随word文档一起保存
                        object saveWithDocument = true;
                        oMissing = System.Reflection.Missing.Value;
                        InlineShape inlineShape = oWord.Selection.InlineShapes.AddPicture(@"" + Application.StartupPath + "\tempImg\shenheName.png", ref linkToFile, ref saveWithDocument, ref oMissing);
                        //设置图片大小
                        inlineShape.Width = 44;
                        inlineShape.Height = 20;

  

原文地址:https://www.cnblogs.com/gaara-zhang/p/11753144.html