1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to modify and save already opened Excel file

Discussão em 'Python' iniciado por Stack, Novembro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have Python script which use data from a .xlsx file and also write to this file. I'm looking for a solution how to proceed script and keep open a .xlsx file.

    Description:

    1. User has opened data.xlsx
    2. Start Python script which reads, writes and saves data to data.xlsx
    3. After the script finishes, the user sees the updated data.xlsx

    import openpyxl
    import datetime

    email_list_path = "d:\\test folder\\data.xlsx"

    wb = openpyxl.load_workbook(email_list_path)

    seznam_adres = wb["mailing list"]

    for i in range(2, 5 + 1):

    verze_emailu = seznam_adres.cell(row=i, column=6).value

    cas = datetime.datetime.now()
    seznam_adres.cell(row=i, column=5).value = cas.strftime('%x %X')

    wb.save('email_list.xlsx')


    I'm useing openpyxl to manage .xlsx file and if I save it wb.save('data.xlsx') I get this error:

    > Traceback (most recent call last):
    > File "D:\\test folder\\Send_email.py", line 141, in \<module\>
    > wb.save('email_list.xlsx')
    >
    > File "D:\\test folder\\venv\\lib\\site-packages\\openpyxl\\workbook\\workbook.py", line 386, in save
    > save_workbook(self, filename)
    >
    > File "D:\\test folder\\venv\\lib\\site-packages\\openpyxl\\writer\\excel.py", line 291, in save_workbook
    > archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
    >
    > File "C:\\Program Files\\Python310\\lib\\zipfile.py", line 1249, in __init__
    > self.fp = io.open(file, filemode)
    > PermissionError: \[Errno 13\] Permission denied: 'email_list.xlsx'

    Continue reading...

Compartilhe esta Página