我了解到可以使用 COM/ActiveX 在 Crystal Reports 中自动生成月度报告.我没有那么先进来理解这是什么,或者你甚至可以用它做什么.
I've read that it is possible to automate monthly reports in Crystal Reports with COM/ActiveX. I'm not that advanced to understand what this is or what you can even do with 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:...Python26Libsite-packageswin32comclient.在 Vista 上,它必须以管理员权限运行.
It provides COM support. You need to run the makepy utility. It is located at C:...Python26Libsite-packageswin32comclient. 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.
包装器是在 C:...Python26Libsite-packageswin32comgen_py 文件夹中生成的 python 模块.该模块包含 COM 对象的接口.文件的名称是 COM 唯一 ID.如果您有很多文件,有时很难找到合适的.
The wrapper is a python module generated in the C:...Python26Libsite-packageswin32comgen_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 做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
python:不同包下同名的两个模块和类python: Two modules and classes with the same name under different packages(python:不同包下同名的两个模块和类)
配置 Python 以使用站点包的其他位置Configuring Python to use additional locations for site-packages(配置 Python 以使用站点包的其他位置)
如何在不重复导入顶级名称的情况下构造python包How to structure python packages without repeating top level name for import(如何在不重复导入顶级名称的情况下构造python包)
在 OpenShift 上安装 python 包Install python packages on OpenShift(在 OpenShift 上安装 python 包)
如何刷新 sys.path?How to refresh sys.path?(如何刷新 sys.path?)
分发带有已编译动态共享库的 Python 包Distribute a Python package with a compiled dynamic shared library(分发带有已编译动态共享库的 Python 包)