简体   繁体   中英

How to password protect a excel file(xlsx) using python

I have been looking at various websites to find a solution of password protect my excel workbook using python but I can't find anything that works. I see couple of solutions where people have protected the file from editing but I need to password protect the entire workbook. Does anyone know how to solve this issue? Here is what I have tried so far but this does not work.

from openpyxl import Workbook
from openpyxl import load_workbook

os.chdir('/Users/Documents')
test_spreadsheet = "ABC.xlsx"
wb = load_workbook(test_spreadsheet)
wb.security.workbookPassword = "password"

Instead of password protection... you could encrypt your excel file with python. I think that is my prefered way of adding security. There are a ton of python libraries for encryption. I have used PyCrypto and had some good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM