在Python中,你可以用COM / ActiveX做什么? [英] What can you do with COM/ActiveX in Python?

查看:872
本文介绍了在Python中,你可以用COM / ActiveX做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我将要在水晶报表中运行每月报表。我已经阅读,你可以自动化与COM / ActiveX,但我不是先进的,以了解这是什么或你甚至可以使用它。

I'm thinking that I'm going to have to run monthly reports in Crystal Reports. I've read that you can automate this with COM/ActiveX but I'm not that advanced to understand what this is or what you can even do with it.

我非常熟悉Python,它看起来像我读过的,我可以打开报告,也许更改一些参数,运行它,并将其导出。

I'm fairly familiar with Python and it looks like from what I've read, I might be able to open the report, maybe change some parameters, run it, and export it.

我也使用Excel做了很多工作,它看起来像你也使用COM / ActiveX接口。

I also do a lot of work with Excel and it looks like you also use COM/ActiveX to interface with it.

有人可以解释这是如何工作的,也许可以提供一个简单的例子。

Can someone explain how this works and maybe provide a brief example?

推荐答案

首先,您必须安装精彩的 pywin32 模组。

First you have to install the wonderful pywin32 module.

它提供COM支持。您需要运行makepy实用程序。它位于C:... \Python26\Lib\site-packages\win32com\client。在Vista上,它必须具有管理员权限。

It provides COM support. You need to run the makepy utility. It is located at C:...\Python26\Lib\site-packages\win32com\client. On Vista, it must be ran with admin rights.

此实用程序将显示所有可用的COM对象。你可以找到你的,它会为这个对象生成一个python包装。

This utility will show all available COM objects. You can find yours and it will generate a python wrapper for this object.

包装是一个python模块生成的C:... \Python26\Lib \site-packages\win32com\gen_py文件夹。模块包含COM对象的接口。文件的名称是COM唯一标识。如果你有很多文件,有时很难找到正确的一个。

The wrapper is a python module generated in the C:...\Python26\Lib\site-packages\win32com\gen_py folder. The module contains the interface of the COM objects. The name of the file is the COM unique id. If you have many files, it is sometimes difficult to find the right one.

之后,你只需要调用正确的界面。这是神奇的:)

After that you just have to call the right interface. It is magical :)

使用excel的简短示例

A short example with excel


import win32com.client

xlApp = win32com.client.Dispatch("Excel.Application")
xlApp.Visible=1

workBook = xlApp.Workbooks.Open(r"C:\MyTest.xls")
print str(workBook.ActiveSheet.Cells(i,1))
workBook.ActiveSheet.Cells(1, 1).Value = "hello"                
workBook.Close(SaveChanges=0) 
xlApp.Quit()

这篇关于在Python中,你可以用COM / ActiveX做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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