使用Python刷新Excel外部数据 [英] Refresh Excel External Data with Python

查看:670
本文介绍了使用Python刷新Excel外部数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行Python脚本的Excel文件. Excel文件具有外部数据连接,在运行Python脚本之前需要刷新这些数据连接.我要指的功能在这里:

I have an Excel file that I run a Python script on. The Excel file has external data connections that need to be refreshed before the Python script is run. The functionality I'm referring to is here:

我使用的是Python 2.7,并且大部分的Excel数据解析都依赖于Pandas.

I'm using Python 2.7 and am relying on Pandas for most of the Excel data parsing.

推荐答案

CalculateUntilAsyncQueriesDone()将保留程序并等待刷新完成.

CalculateUntilAsyncQueriesDone() will hold the program and wait until the refresh has completed.

xlapp = win32com.client.DispatchEx("Excel.Application")
wb = xlapp.Workbooks.Open(<path_to_excel_workbook>)
wb.RefreshAll()
xlapp.CalculateUntilAsyncQueriesDone()
wb.Save()
xlapp.Quit()

这篇关于使用Python刷新Excel外部数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆