小编Oma*_*eed的帖子

Password Protecting an Excel file using Python

I am trying to password protect an entire Excel file (same functionality as File > Protect Workbook > Encrypt with Password) using Python.

I have come across openpyxl and the protection features it offers (https://openpyxl.readthedocs.io/en/stable/protection.html) seems to fulfill this need. I have the following code:

from openpyxl import Workbook
from openpyxl import load_workbook

test_spreadsheet = "test.xlsx"
wb = load_workbook(test_spreadsheet)
wb.security.workbookPassword = "password"
Run Code Online (Sandbox Code Playgroud)

However, I am getting the following error:

AttributeError: 'NoneType' object has no attribute 'workbookPassword'

Does anyone …

python excel openpyxl

6
推荐指数
1
解决办法
2086
查看次数

标签 统计

excel ×1

openpyxl ×1

python ×1