0

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"
Beginner
  • 57
  • 2
  • 10
  • Does this answer your question? [Password Protecting Excel file using Python](https://stackoverflow.com/questions/36122496/password-protecting-excel-file-using-python) – Norhther May 26 '21 at 16:56
  • I tried the solution listed here but it did not work. It password protected the worksheet but not the workbook. – Beginner May 26 '21 at 16:58

1 Answers1

0

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.

  • How will decryption work? I have to send this file to non technical users so I have to ensure that they can open the file easily at their end. – Beginner May 26 '21 at 17:02
  • you can send over a decryption script along with the file itself, maybe separately. The thing is... you may want to expand your stack from python because I have not been able to find anything from just python alone. or.. send a pdf instead of excel. PDFs can easily be password protected – killersquid May 26 '21 at 17:11