Set workbook password doesn't work
Created originally on Bitbucket by Ron
Hello,
I have a problem I can’t figure out….
I'm using openpyxl to export excel in vision 2.6.2. And I want to set the password of this workbook. At first, I use security.set_workbook_password
,but there is an error that doesn’t have this modules. I use dir() and found security
doesn’t have the member of set_workbook_password.
So I define it by my self and it work. The member workbook_password of security
have the value. But it doesn't work when I open the excel what I just create by python.
from openpyxl.workbook.protection import WorkbookProtection
from openpyxl import load_workbook, Workbook
wb = load_workbook('\sample.xlsx')
hashed_password = 'asd'
wb.security = WorkbookProtection()
wb.security.set_workbook_password(hashed_password, already_hashed=True)
wb.save('\sample1111111.xlsx')
Can someone help me to solve this problem?