Is there a better way (besides COM) to remote-control Excel?(有没有更好的方法(除了COM)来远程控制Excel?)
问题描述
我正在开发一种回归测试工具,该工具将验证大量 Excel 电子表格.目前,我使用最新版本的 pywin32 产品通过 Python 脚本通过 COM 控制它们.不幸的是,COM 似乎有许多恼人的缺点:
I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks:
例如,最轻微的干扰似乎能够断开与 COM-Server 的连接,一旦断开,似乎没有安全的方法可以重新连接到 Excel 应用程序.COM 应用程序对象中绝对没有内置安全性.
For example, the slightest upset seems to be able to break the connection to the COM-Server, once severed there seems to be no safe way to re-connect to the Excel application. There's absolutely no safety built into the COM Application object.
Excel COM 接口不允许我安全地远程控制在同一个工作簿文件上运行的 Excel 应用程序的两个单独实例,即使它们是只读的.
The Excel COM interface will not allow me to safely remote-control two seperate instances of the Excel application operating on the same workbook file, even if they are read-only.
此外,当确实出现问题时,我很少收到任何有用的错误消息……最多只能是数字错误代码或几乎没有用的消息,例如发生异常".几乎不可能知道为什么会出错.
Also when something does go wrong I seldom get any useful error-messages... at best I can except a numerical error-code or a barely useful message such as "An Exception has occurred". It's almost impossible to know why something went wrong.
最后,COM 缺乏控制 Excel 一些最基本方面的能力?例如,没有办法保证只关闭 COM 客户端所连接的 Excel 进程.你甚至不能使用 COM 来查找 Excel 的 PID.
Finally, COM lacks the ability to control some of the most fundamental aspects of Excel? For example there's no way to do a guaranteed close of just the Excel process that a COM client is connected to. You cannot even use COM to find Excel's PID.
如果我完全放弃 COM 怎么办? 是否有其他方法来控制 Excel?
So what if I were to completely abandon COM? Is there an alternative way to control Excel?
我只想运行宏、打开和关闭工作簿以及读取和写入单元格范围?也许一些 .NET 专家知道一两个还没有进入 Python 社区的技巧?你们办公室的黑客呢?有没有比 COM 更好的方法来了解 Excel 的内脏?
All I want to do is run macros, open and close workbooks and read and write cell-ranges? Perhaps some .NET experts know a trick or two which have not yet bubbled into the Python community? What about you office-hackers? Could there be a better way to get at Excel's innards than COM?
推荐答案
没有办法完全绕过COM.您可以使用 VSTO(Visual Studio Tools for Office),它在 COM 对象上有很好的 .NET 包装器,但它在下面仍然是 COM.
There is no way that completely bypasses COM. You can use VSTO (Visual Studio Tools for Office), which has nice .NET wrappers on the COM objects, but it is still COM underneath.
这篇关于有没有更好的方法(除了COM)来远程控制Excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有更好的方法(除了COM)来远程控制Excel?
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01