gpt4 book ai didi

Windows 服务中的 Excel OLE 自动化

转载 作者:行者123 更新时间:2023-12-03 20:23:40 25 4
gpt4 key购买 nike

我有一个 Windows 服务通过 OLE 自动化填充 Excel 工作簿中的单元格。

保存过程不工作,文件永远不会保存。但在 GUI 应用程序中完成时,保存过程有效。

服务用户是管理员帐户。我怀疑与桌面的交互。

有什么想法吗?

最佳答案

不要这样做。寻找其他解决方案。微软does not support or recommend从工作站桌面 session 以外的任何地方对 Office 软件进行 OLE 自动化。我无法解释比他们直接说的更好的解释,所以这里是建议(上面的链接更详细):

All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.

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.

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.

如果您的服务需要存储数据,数据库可能是一个不错的选择。任何需要 Excel 电子表格中的数据的用户都可以从数据库中填充他们的文档。您甚至可以设置模板文档来自动执行此操作。

关于Windows 服务中的 Excel OLE 自动化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60304877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com