Is there a better way (besides COM) to remote-control Excel?

前端 未结 5 426
有刺的猬
有刺的猬 2021-01-07 08:55

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 l

相关标签:
5条回答
  • 2021-01-07 09:30

    You could use Jython with the JExcelApi (http://jexcelapi.sourceforge.net/) to control your Excel application. I've been considering implementing this solution with one of my PyQt projects, but haven't gotten around to trying it yet. I have effectively used the JExcelApi in Java applications before, but have not used Jython (though I know you can import Java classes).

    NOTE: the JExcelApi may be COM under the hood (I'm not sure).

    0 讨论(0)
  • 2021-01-07 09:37

    Have you looked at the xlrd and xlwt packages? I'm not in need of them any more, but I had good success with xlrd on my last project. Last I knew, they couldn't process macros, but could do basic reading and writing of spreadsheets. Also, they're platform independent (the program I wrote was targetted to run on Linux)!

    0 讨论(0)
  • 2021-01-07 09:40

    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.

    0 讨论(0)
  • 2021-01-07 09:40

    It is also possible to run Excel as a server application and use it as a calculation engine. This allows non IT users to specify business rules within Excel and call them through webservices. I have not worked with this myself, but I know a coworker of mine used this once. Walkthrough: Developing a Custom Application Using Excel Web Services could be a good starting point. A first glance at that page looks like it requires Sharepoint. This might not be suiteable for every environment.

    0 讨论(0)
  • 2021-01-07 09:41

    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.

    This is not a limitation of COM, this is a limitation of Excel. Excel will not even let you open two files with the same name at the same time if they exist in different directories. It is a fundamental limitation of the Excel program.

    To answer your other questions

    If you check your python documentation, there should be a way to connect to an existing server if the connection is lost.

    The lack of useful error messages again may be to do with Python.

    You cannot even use COM to find Excel's PID.

    COM is an internal object model and exposed what it wishes. PID are available to outside processes as much as they are to internal, there is no real reason to expose as a COM interface.

    0 讨论(0)
提交回复
热议问题