如何禁止“更新链接"带有xlwings的警报 [英] How to suppress "Update Links" Alert with xlwings

查看:619
本文介绍了如何禁止“更新链接"带有xlwings的警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xlwings api与Python中的Excel文件进​​行接口.我正在与之交互的某些Excel文件具有旧链接,当打开文件时,该提示会出现提示,询问用户是否要更新链接.这将导致代码无限期地挂在打开书的行上,直到用户关闭此提示为止.有没有一种方法可以修改Excel文件的设置,使该提示不出现,或者在不打开实际文件的情况下自动消失?

I am interfacing with Excel files in Python using the xlwings api. Some Excel files I am interacting with have old links which cause a prompt to appear when the file is opened asking if the user would like to update the links. This causes the code to hang indefinitely on the line that opened the book until this prompt is closed by a user. Is there a way to modify the settings of the Excel file so that this prompt will not appear or it will be automatically dismissed without opening the actual file?

我尝试使用xlwings方法:

I have tried using the xlwings method:

xlwings.App.display_alerts = False

禁止显示提示,但据我所知,只能在Excel实例打开后才能运行.有些Excel api不需要打开文件即可读取xlrd之类的数据,但是它们对于读取和复制大量数据(多张/整张数据)不是很方便.

to suppress the prompt, but as far as I can tell this can only be run for an instance of Excel after it has been opened. There are some Excel api's that do not require a file to be open in order to read data like xlrd, but they are not very convenient for reading and copying large amounts of data (Multiple/Entire sheets of data).

以下代码演示了该问题:

The following code demonstrates the issue:

import xlwings as xw

wb = xw.Book(r'C:\Path\To\File\Filename')

print('Done')

在常规Excel文件中,代码继续进行并打印完成",而无需用户干预,但是在出现更新链接"提示的Excel文件中,直到提示出现时,该文件才继续执行打印语句被用户关闭.

On a regular Excel file the code proceeds through and prints "Done" without the need of user interference, but on an Excel file where the "update links" prompt comes up, it will not proceed to the print statement until the prompt is dismissed by a user.

推荐答案

第一次尝试扩展-您没有在处理App实例,而是在尝试分配给xlwings.App类.

Expanding on your first attempt -- you're not handling an App instance, rather you're trying to assign to the xlwings.App class.

但是,似乎 display_alerts无法成功抑制此警报xlwings中,尝试以下操作:

However, it seems that the display_alerts doesn't successfully suppress this alert in xlwings, try this:

import xlwings as xw
app = xw.App(add_book=False)
app.display_alerts = False
wb = app.books.api.Open(fullpath, UpdateLinks=False)

这篇关于如何禁止“更新链接"带有xlwings的警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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