在ASP.net MVC6网站上使用Office Interop [英] Use Office Interop on ASP.net MVC6 website

查看:288
本文介绍了在ASP.net MVC6网站上使用Office Interop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的ASP.net MVC 6网站生成Word文档。我已经实现了几种方法在POC中生成文档:DocX,NetOffice,OpenXml,COM Interop对象。我被它诱惑了。

I want to generate word documents from my ASP.net MVC 6 website. I've implemented several ways to generate a document in a POC : DocX, NetOffice, OpenXml, COM Interop objects. I was seduced by it.

我做了一个控制台应用程序来测试,它工作。

I made a Console App to test and it works.

ASP.net MVC6,我们不能引用控制台应用程序或COM程序集。
我们需要创建控制台应用程序(包)。

But, with ASP.net MVC6, we can't reference Console App's or COM Assemblies. We need to create "Console App (Package)".

如何添加COM程序集到我的ASP.net MVC 6网站?

How can I add COM Assemblies to my ASP.net MVC 6 website ?

推荐答案

Microsoft目前不推荐,也不支持从任何无人值守,非交互式客户端应用程序自动化Microsoft Office应用程序,组件(包括ASP,ASP.NET,DCOM和NT服务),因为当Office在此环境中运行时,Office可能会显示不稳定的行为和/或死锁。

如果您正在构建在服务器端上下文中运行的解决方案,则应尝试使用对无人值守执行安全的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。如果从服务器端解决方案使用Office应用程序,则应用程序将缺少许多必需的功能来成功运行。此外,您将采取整体解决方案的稳定性风险。

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

您可以在服务器端自动化Office 的注意事项。

You can read more about that in the Considerations for server-side Automation of Office article.

请考虑使用专为服务器端执行设计的第三方组件,或者如果您处理打开的XML文档,可以使用Open XML SDK,请参阅欢迎使用Open XML SDK 2.5 for Office 有关更多信息。

Consider using third-party components designed for the server-side execution or if you deal with open XML documents you may use the Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information.

这篇关于在ASP.net MVC6网站上使用Office Interop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆