How to insert image in a existing word document with c#

。_饼干妹妹 提交于 2021-01-28 14:22:45

问题


I am working with word and c# . taking the snap shot with my code and saving it in a particular folder (ex.C:\Temp). now i want to save the image to an existing word document.any kind of help with short code sample is highly appreciated .
Will prefer to use Microsoft.Office.Interop.Word;


回答1:


Of course, the Word object model provides the required methods for inserting an image into the document. To add a picture at the cursor location you just need to call the AddPicture method of the InlineShapes collection and pass in the name of the file.

 Application.Selection.InlineShapes.AddPicture(@"C:\SamplePicture.jpg");

See How to: Programmatically Add Pictures and Word Art to Documents for more information.

Also you may consider using the Open XML SDK. Take a look at the following articles in MSDN:

  • How to: Insert a picture into a word processing document (Open XML SDK)
  • Adding Images to Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office


来源:https://stackoverflow.com/questions/29400201/how-to-insert-image-in-a-existing-word-document-with-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!