I am trying to find pythonic ways to encrypt/password-protect excel xlsx files. Came across openpyxl, where in their documentation (https://openpyxl.readthedocs.io/en/stable/protection.html) states that it can do so.
However, an error message AttributeError: 'NoneType' object has no attribute 'workbookPassword'
is prompted when I executed the following. Help anyone?
from openpyxl import workbook
file = 'test.xlsx' // an existing xlsx
wb = load_workbook(filename = file)
wb.security.workbookPassword = 'test_password'
wb.security.lockStructure = True
Edit:
I believe I have used the function improperly, though it is not v clear in their documentation. It was also mentioned that the password can be set using this function openpyxl.workbook.protection.WorkbookProtection.workbookPassword()
, which then differs in their example.