通过C#编写的Windows服务通过Excel自动化在Office 365安装的计算机中失败 [英] Excel Automation through Windows Service written in C# fails in Office 365 installed machines

查看:117
本文介绍了通过C#编写的Windows服务通过Excel自动化在Office 365安装的计算机中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用用C#编写的Windows服务.通过此Windows服务,我以编程方式自动执行Excel.

I am working with Windows Service written in C#. Through this Windows Service I am automating Excel in a programmatic way.

Excel.Application excel = Excel.Application();

此代码在所有版本的Excel(2003、2007、2010、2013)中均能正常工作. 最近,我在计算机上安装了Office 365.突然,当我使用上面的调用自动执行Excel时,我遇到了以下异常:

This code was working fine with all versions of Excel (2003, 2007, 2010, 2013). Recently I have installed Office 365 in my machine. Suddenly I am getting below exception when I automate the Excel using above call:

由于以下错误,检索具有CLSID {00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80080005服务器执行失败(HRESULT异常:0x80080005(CO_E_SERVER_EXEC_FAILURE)).

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

任何人都可以让我知道,通过Windows Service自动化Office 365 Excel时应该采取什么特殊的考虑吗?

Can anyone let me know, is there any special consideration should be taken when automating the Office 365 Excel via Windows Service?

推荐答案

Microsoft当前不建议也不支持任何无人参与的非交互客户端应用程序或组件(包括ASP,ASP)中的Microsoft Office应用程序自动化. NET,DCOM和NT服务),因为在这种环境下运行Office时,Office可能表现出不稳定的行为和/或死锁.

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.

如果要构建在服务器端上下文中运行的解决方案,则应尝试使用对无人值守执行安全的组件.或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法.如果您使用服务器端解决方案中的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. Read more about that in the Considerations for server-side Automation of Office article.

您可以考虑改用Open XML SDK,请参见

You may consider using the Open XML SDK instead, see EWS Managed API, EWS, and web services in Exchange for more information. Or any third-party components designed for the server-side execution.

这篇关于通过C#编写的Windows服务通过Excel自动化在Office 365安装的计算机中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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