首页 > 解决方案 > xlwings 错误:pywintypes.com_error:(-2147352573,'未找到成员。',无,无)

问题描述

我打开了一个 Excel,其中包含 RTD 流数据(来自交易平台的财务数据)。我的目标是通过 Python 读取数据并在数据更改后立即保存。目标是捕捉每一毫秒。我正在使用 xlwings 读取单元格值,但通常在 50-100 次尝试后我得到了同样的错误。知道如何解决吗?

import xlwings as xw

n_of_times_checked=0
while True:
    n_of_times_checked +=1
    print("Cell value:",xw.Range("D41").value," Num of times checked:",n_of_times_checked)

结果:

Cell value: 55.0  Num of times checked: 71
Cell value: 55.0  Num of times checked: 72
Cell value: 55.0  Num of times checked: 73
Cell value: 55.0  Num of times checked: 74
Cell value: 55.0  Num of times checked: 75
Traceback (most recent call last):
  File "D:/Google drive/Python/Backtesting/backtesting_uj/RTD_recorder.py", line 7, in <module>
    print("Cell value:",xw.Range("D41").value," Num of times checked:",n_of_times_checked)
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\main.py", line 999, in __init__
    impl = apps.active.range(cell1).impl
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\main.py", line 392, in range
    return Range(impl=self.impl.range(cell1, cell2))
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\_xlwindows.py", line 401, in range
    xl1 = self.xl.Range(arg1)
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\_xlwindows.py", line 63, in __call__
    v = self.__method(*args, **kwargs)
  File "<COMObject <unknown>>", line 2, in Range
pywintypes.com_error: (-2147352573, 'Member not found..', None, None)

标签: pythonxlwings

解决方案


我正在寻求帮助,因为我没有得到,作为你的价值,我只是得到#¿NAME?使用我的代码虽然键入 F2 F9 得到正确的值(rtd.tos)。无论如何,我想问题是您的代码在更改/刷新时查找值时崩溃,所以我建议使用 try/except 包装您的打印语句。另外,请注意 rtd 的刷新率根据 Application.RTD.ThrottleInterval 值(默认为 1 秒)。


推荐阅读