我打开了一个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)
答案 0 :(得分:0)
我一直在寻求帮助,因为我没有得到您所知道的值,只是得到#¿NAME?我的代码,虽然键F2 F9获得正确的值(rtd.tos)。 无论如何,我想问题是您的代码在更改/刷新时查找值时代码崩溃,因此我建议您使用try / except包装您的打印语句。 另外,请注意rtd的刷新速率应为Application.RTD.ThrottleInterval值(默认为1秒)。