如何使用C#在现有Word文档中插入图像

问题描述:

我正在使用 word c#.用我的代码拍摄快照并将其保存在特定的文件夹中(例如C:\ Temp).现在,我想将图像保存到现有的Word文档中.对简短代码示例的任何帮助都将受到高度赞赏.
宁愿使用 Microsoft.Office.Interop.Word ;

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;

当然,Word对象模型提供了将图像插入文档的必需方法.要在光标位置添加图片,您只需调用AddPicture 方法"rel =" nofollow> InlineShapes 集合,并传入文件名.

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");

请参见如何:以编程方式将图片和艺术字添加到文档中有关更多信息.

您也可以考虑使用Open XML SDK.看一下MSDN中的以下文章:

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