首页 > 解决方案 > 使用 python 在 excel 上加载 Bloomberg 插件时遇到问题

问题描述

我正在尝试打开一个连接到 BBG 并刷新值的 excel。

要打开一个 excel 实例并加载bloomberg 插件,我之前使用了附加链接中的一个解决方案 Python using win32com wont update excel sheet with required Add-ins

该解决方案对我来说一直很好,直到今天由于某种原因xlapp.RegisterXLL('C:/blp/API/Office Tools/bofaddin.dll')给我带来了麻烦。即不加载和崩溃我的代码。

任何人有任何想法发生了什么?

如果有人感兴趣,代码如下

import os, os.path
import win32com.client

xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.RegisterXLL('C:/blp/API/Office Tools/bofaddin.dll')
xlapp.Workbooks.Open('C:\\blp\\API\\Office Tools\\BloombergUI.xla')
wb = xlapp.Workbooks.Open(filepath,None,False)
xlapp.Visible = True
wb_addin = ('C:/blp/API/Office Tools/bofaddin.dll')
wb.RefreshAll()

标签: pythonwin32combloomberg

解决方案


尝试导入时间并将 time.sleep(2) 放在每个命令之后。我发现彭博链接有时需要一秒钟才能更新。

xlapp = win32com.client.DispatchEx("Excel.Application")
time.sleep(2)
xlapp.RegisterXLL('C:/blp/API/Office Tools/bofaddin.dll')
time.sleep(2)
xlapp.Workbooks.Open('C:\\blp\\API\\Office Tools\\BloombergUI.xla')
time.sleep(2)
wb = xlapp.Workbooks.Open(filepath,None,False)
xlapp.Visible = True
wb_addin = ('C:/blp/API/Office Tools/bofaddin.dll')

推荐阅读