有没有更好的方法(除了COM)远程控制Excel的? [英] Is there a better way (besides COM) to remote-control Excel?

查看:143
本文介绍了有没有更好的方法(除了COM)远程控制Excel的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个回归测试工具,将验证大量的Excel US preadsheets。目前我使用的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-服务器,一旦切断似乎有没有安全的方式来重新连接到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.

此外,当确实存在错误我很少得到任何有用的错误信息......在尽我所能除外数值无差错code或勉强有用的信息,如发生了异常。这几乎是不可能知道为什么出事了。

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社区?那你的办公室,黑客?难道还有更好的方式来获得在Excel的内部结构比COM?

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工具用于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的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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