gpt4 book ai didi

python - xlwings错误: pywintypes. com_error : (-2147352573, 'Member not found.',无,无)

转载 作者:行者123 更新时间:2023-12-01 08:08:24 24 4
gpt4 key购买 nike

我打开了一个 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 秒)。

关于python - xlwings错误: pywintypes. com_error : (-2147352573, 'Member not found.',无,无),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55422990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com