Create word document and add image from .NET app

我与影子孤独终老i 提交于 2019-12-11 01:48:15

问题


I need a way of generating a word document (from a template or something) and inserting an image at a specific place. Does anyone have any pointers on the best way to do this?

I worked on a project that used Office Automation in .NET 1.1 a few years ago, and it was really unspeakably poor. I'm assuming OA has either been improved or been superceeded by a better solution, but I'm not finding much advice on google.

Edit to clarify, this will be running on a web or sharepoint server


回答1:


Alternatively, and if you do not need to generate word documents that will work with versions prior to Word 2007, you could use the OpenXML SDK to create your Word Document. It's all managed code and way easier in my opinion to use than OA.




回答2:


Having done something very similar, I would advise against it. Office Automation within a server environment is buggy. Further the COM Interop requires an interactive user, i.e. there is no 'headless' mode.

Use OpenXML as suggested by Gimly, this would be cleaner approach.




回答3:


Following line would add the image to word document.

wordDoc.InlineShapes.AddPicture(filePath, ref  link, ref  save, ref  range);

Here, link should be false and save should be true. Range should be the location where you need to add image.

This link should help out dealing with the Interop.



来源:https://stackoverflow.com/questions/2804531/create-word-document-and-add-image-from-net-app

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