Windows 服务中的 Excel OLE 自动化

标签 excel delphi ole

我有一个 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/

相关文章:

.net - 如何将WPF应用程序制作为可以嵌入MS Excel中的OLE对象?

events - 处理运行时创建的 OLEObject 命令按钮的事件

java - 如何将文件对象插入(嵌入)到 Excel 工作表中

java - 使用Apache POI在Excel中使用千位分隔符格式化数字

delphi - IdHTTP + socks + socks 5

c++ - 字2013 : OLE in place editing not working?

vba - Excel SpecialCells(xlCellTypeBlanks) 合并单元格失败

c# - 将 Excel 数据加载到 SQL 服务器中 - 添加了额外的 NULL 行

delphi - Google OAuth 与 Delphi 中的 Indy

delphi - 放大 TVVirtualStringTree