如何检查大型Excel文件是否尽快得到保护? [英] How to check if a large Excel file is protected as quickly as possible?

查看:88
本文介绍了如何检查大型Excel文件是否尽快得到保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以最快的方式检查excel文件是否受密码保护(无需尝试打开它并放置异常)?

How to check if excel file is protected with password the fastest way (without trying to open it and placing an exception)?

已更新:

from zipfile import *
from openpyxl import load_workbook
filename = 'Z:\\path_to_file\\qwerty.xlsm' # protected one
try:
    wb = load_workbook(filename, data_only=True, read_only=True) 
except (BadZipfile) as error:
    print(is_zipfile(filename))

一个问题是我得到了False作为输出,因此我无法摆脱异常并将其替换为is_zipfile()条件.

A problem is that I got False as an output, thus I cannot get rid of the exception and replace it with is_zipfile() condition.

推荐答案

当尝试使用openpyxl打开受密码保护的工作簿时,这的确给出了一个zipfile.BadZipFile错误,因此可以使用以下解决方法:

When trying to open a password protected workbook with openpyxl, this indeed gives a error zipfile.BadZipFile so a workaround would be to use:

import zipfile
zipfile.is_zipfile("workbook.xlsx")

这篇关于如何检查大型Excel文件是否尽快得到保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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