Python教程:[52]win32com调用constants

2024-10-24 19:47:52

今天使用python的win32com组间操作Excel的时候发现一个问题,想要使用常数consta荏鱿胫协nts.xlUp,但是却总是提示错误:

Traceback (most recent call last):

File "<pyshell#1>", line 1, in <module>

c.xlUp

File "D:\Python27\lib\site-packages\win32com\client\__init__.py", line 170, in __getattr__

raise AttributeError(a)

AttributeError: xlUp

百度一下也没结果,后来求助于Google,就找到了答案,现在写在这里。

我来介绍一下自己的代码吧,先来引入常量constantsPython教程:[52]win32com调用constants

接着,我们引入client,这都是操作Excel的时候用到的基本模块Python教程:[52]win32com调用constants

现在我们启动一下Excel,句柄存在xl中Python教程:[52]win32com调用constants

我们尝试调用一下c.xlUp,看到了吧,提示错误Python教程:[52]win32com调用constants

假如,我现在用另一个方式启动ExcelPython教程:[52]win32com调用constants

现在就可以正确读取了Python教程:[52]win32com调用constants

我现在还不知道这两种方式到底有什么区别,只能先写到这里,如果哪位朋友知道为什么,可以在下面留言。

猜你喜欢