我有一个外部数据连接的excel文件。我需要使用python刷新连接数据。在
我试过苏打
import win32com.client
import os
fileName="testconn.xlsx"
xl = win32com.client.DispatchEx("Excel.Application")
wb = xl.workbooks.open(fileName)
xl.Visible = True
wb.RefreshAll()
wb.Save()
xl.Quit()
但是这个解决方案需要在机器上安装excel。在
我认为另一种方法是: -如果我知道如何获得数据连接的URL和加载它们的命名范围的映射,我可以从URL下载数据并使用openpyxl更新命名范围中的数据。在
有更好的方法吗?任何python库都有检索连接和刷新连接的功能吗?在
提前感谢:)
刷新Excel工作表肯定需要安装Excel。所以你的方法似乎很好,尽管可能有更简单的方法。Pandas有一个很好的库来操作Excel电子表格
pandas.read_excel
和pandas.DataFrame.to_excel
函数http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.htmlhttp://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html但仅使用Pandas无法写入命名区域,它至少需要指定工作表和起始单元格(如果命名区域不更改起始单元格/工作表,则很好)。{可以在此处使用另一个名为^的包来添加一个名为^的包: http://xlsxwriter.readthedocs.io/example_defined_name.html#ex-defined-namehttps://xlsxwriter.readthedocs.io/working_with_pandas.htmlPandas还允许您直接从URL读取数据,这将有助于您提出的解决方案
pandas.read_html
。http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_html.html相关问题 更多 >
编程相关推荐