Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88075

openpyxl: password protect entire excel file (xlsx)

$
0
0

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.


Viewing all articles
Browse latest Browse all 88075

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>