我有一堆 excle 表,可以提取 bloomberg 日终数据,我将这些数据用于 Python 中的各种用途。我的问题如下:
有没有办法告诉 sheet 刷新 bloomberg 数据?
传统的刷新全部不起作用,就像在excel中按f9不会刷新它们一样。我知道如何做到这一点的唯一方法是在 bloomberg 选项卡下单击(在 excel 中)刷新图标,两个箭头。我很乐意将其自动化。
这是我现在拥有的:
import win32com.client
import time
def refr_sheet():
app_global = win32com.client.Dispatch("Excel.Application")
global_sprdsheet = app_global.Workbooks.open('C:\\Users\\Ako\\Desktop\\ako_files\\work_sheets\\global.xlsx')
global_sprdsheet.RefreshAll()
time.sleep(12)
global_sprdsheet.Save()
global_sprdsheet.Close()
app_global.Quit()
它适用于重新计算一般的 excel 计算公式,但不会刷新 bloomberg(=BHD 类型)公式。
欢迎提出任何建议!
请您参考如下方法:
有两种选择: 简单的解决方案 在工作表中创建宏(需要制作文件 xlsm 而不是 xlsx)
sub refresh_bbg()
'depending on your setup may be worth checking Bloomberg api is installed here and installing if not.
Application.Run ("bloombergui.xla!RefreshEntireWorkbook")
end sub
然后在 python 中
global_sprdsheet.Application.Run("global.xlsm!refresh_bbg")
但我认为更好的解决方案是通过 tia 或 pdblp 在 python 中收集 bbg 数据。然后将数据写入文件。根据我的经验,这更可靠。
