在openpyxl中保护工作簿 [英] Protecting Workbook in openpyxl

查看:412
本文介绍了在openpyxl中保护工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用openpyxl保护Excel工作簿.

I try to protect an Excel workbook with openpyxl.

到目前为止,我已经研究了不同的,可能相关的类,但是我找不到像

So far I had a look into the different, potentially relevant classes but I can't find a set_password method like the one for worksheets.

碰巧有 workbook.protection 模块.我的代码归结为绝对相关的最小值,如下所示:

There happens to be the workbook.protection module that I tried my luck with. My code, boiled down to the absolute relevant minimum is as follows:

from openpyxl import Workbook
from openpyxl.workbook.protection import WorkbookProtection

wb = Workbook()
wb.security = WorkbookProtection(workbookPassword='0000', revisionsPassword = '0000', lockWindows = True, lockStructure = True, lockRevision = True)
wb.create_sheet("testSheet")
wb.save("test.xlsx")

我没有收到任何错误,但也没有得到任何保护.任何帮助将不胜感激.

I don't get any errors but no protection either. Any help would be dearly appreciated.

推荐答案

当前在Openpyxl(v2.4.8)中不起作用-密码未写入输出文件.为此有一个开放的PR( https://bitbucket.org/openpyxl/openpyxl/pull-requests/180/read-and-write-workbook-protection/diff ),因此希望它将包含在以后的版本中.

This doesn't currently work in Openpyxl (v2.4.8) - the password is not written to the output file. There is an open PR for this (https://bitbucket.org/openpyxl/openpyxl/pull-requests/180/read-and-write-workbook-protection/diff), so hopefully it will be included in future releases.

这篇关于在openpyxl中保护工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆