python - 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)
解决方案
我正在寻求帮助,因为我没有得到,作为你的价值,我只是得到#¿NAME?使用我的代码虽然键入 F2 F9 得到正确的值(rtd.tos)。无论如何,我想问题是您的代码在更改/刷新时查找值时崩溃,所以我建议使用 try/except 包装您的打印语句。另外,请注意 rtd 的刷新率根据 Application.RTD.ThrottleInterval 值(默认为 1 秒)。
推荐阅读
- flutter - 在颤振中从 API 访问数据
- python - 在python中创建一个wilcoxon秩和测试的for循环以生成p值列表?
- ios - 在 SwiftUI 3 中交换选项卡视图指示器的配色方案
- python - 使用 Python 日志记录消息和标准错误
- json - 带 curl 的 Keycloak POST(创建用户和组)
- javascript - 使变量与对象方法相等
- windows - 如何检测正在进行的 webex 会议或 google 会议
- bash - 如何使用自定义文件夹中的所有脚本,例如 macOS 中的本机 shell 命令
- javascript - 在本地捕获 mux.monitor 对象
- python - 如何从不同表中的字段创建复合外键?