c# word 插入圖片問題

情景描述:佈局

  在以前文本框中加標籤,代碼直接addPicture出現了意外。不起做用,懷疑是文檔模板的問題,由於生成的PDF和word格式總時不時有差別,左右搗鼓下,更換文本框,更換圖片形式,形狀形式,放成最大,佈局格式調整,絕對位置調整,都不行。設計

原理描述:orm

  在文檔行不通的時候,或者能夠把文檔模板從新設計抑或文檔模板中直接添加上,判斷狀況刪去。無疑都是很麻煩。這個時候決定換種插入圖片的方法,行得通。blog

代碼附上:圖片

//查找書籤
                        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;
相關文章
相關標籤/搜索