I try to protect an Excel workbook with openpyxl.
So far I had a look into the different, potentially relevant classes but I can't find a set_password
method like the one for worksheets.
There happens to be the workbook.protection module that I tried my luck with. My code, boiled down to the absolute relevant minimum is as follows:
from openpyxl import Workbook
from openpyxl.workbook.protection import WorkbookProtection
wb = Workbook()
wb.security = WorkbookProtection(workbookPassword='0000', revisionsPassword = '0000', lockWindows = True, lockStructure = True, lockRevision = True)
wb.create_sheet("testSheet")
wb.save("test.xlsx")
I don't get any errors but no protection either. Any help would be dearly appreciated.