[Python] How to Bypass "Grant Access" when using Xlwings

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am in the process of porting over some python excel automation scripts to work on MacOS (previously they were run on windows, and used the pywin32 library to "refresh" an excel file - the purpose of this was to make sure that all formulas were computed before using pandas to read the excel file to a data frame).

    I have run into a problem, where when I try and open an excel file using xlwings I get a popup asking to "Grant Access" as seen in the image below:

    [​IMG]

    I tried making sure Excel and python have Full Disk Access, I have tried changes my Excel security settings to allow anyone to read/write, but nothing seems to solve this (besides for clicking "Grant Access", but this script will be parsing many excel files and manually handling these popups are not feasible).

    Here is the code that triggers the popup:

    try:
    import xlwings as xw # type: ignore

    with xw.App(visible=False) as app:
    try:
    app.display_alerts = False
    app.screen_updating = False
    except Exception:
    pass

    # HERE IS WHERE THE GRANT ACCESS POPUP IS TRIGGERED
    wb = app.books.open(file_path, update_links=False)
    try:
    app.calculate()
    except Exception:
    pass
    wb.save()
    wb.close()
    logging.info("Excel formulas refreshed via xlwings")
    return
    except Exception as e:
    logging.info(f"xlwings refresh unavailable or failed: {e}")

    Continue reading...

Compartilhe esta Página