Is using Interop the recommended method when auto-

2019-09-19 15:25发布

问题:

As stated in the title, I need to do some C# coding from a Web Application that will auto-generate a Word document. So far, targeted towards Office 2007 and above users.

My question would be, is using the Interop library the recommended way of doing this? Isn't there some issues with using it between different versions (e.g. 2007 -> 2010 -> 2013)? What are its advantages and disadvantages? And finally, are there any better alternatives?

回答1:

On the contrary, Microsoft's advice is very much not to use it:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

There are various libraries available in managed code (OpenXML SDK, Aspose Words etc.)



回答2:

As Charles metnioned, Microsoft doesn't recommend automating Office applications on the server (from any unattended client). Instead, I'd suggest using the Open XML SDK for buiding open XML file format Office files. See Welcome to the Open XML SDK 2.5 for Office for more information.