Home » excel » python – How to suppress "Update Links" Alert with xlwings

python – How to suppress "Update Links" Alert with xlwings

Posted by: admin April 23, 2020 Leave a comment


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?

I have tried using the xlwings method:

xlwings.App.display_alerts = False

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')


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.

How to&Answers:

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

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)