[Python] How to open encrypted xlsb file?

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    I used this code for open encrypted .xlsx files and it's work.

    path_to_my_file = r'filename.xlsx'
    passwd = 'pwd'


    decrypted_workbook = io.BytesIO()
    with open(path_to_my_file , 'rb') as file:
    office_file = msoffcrypto_OfficeFile(file)
    office_file.load_key(password=passwd)
    office_file.decrypt(decrypted_workbook)


    but when I use this code for read .xlsb protected file then I have error

    DecryptionError Traceback (most recent call last)
    Cell In[56], line 5
    3 office_file = msoffcrypto_OfficeFile(file)
    4 office_file.load_key(password=passwd)
    ----> 5 office_file.decrypt(decrypted_workbook)

    File C:\ProgramData\anaconda3\Lib\site-packages\msoffcrypto\format\ooxml.py:287, in OOXMLFile.decrypt(self, outfile, verify_integrity)
    285 outfile.write(obuf)
    286 elif self.type == "plain":
    --> 287 raise exceptions.DecryptionError("Unencrypted document")
    288 else:
    289 raise exceptions.DecryptionError("Unsupported encryption method")

    DecryptionError: Unencrypted document


    Does anyone know the solutions to this problem?

    I used this source https://pythoninoffice.com/read-encrypted-excel-file-using-pandas/

    Continue reading...

Compartilhe esta Página