上代码
import pyexcelerator
def test_passwords(filepath, passwords):
# 读取加密文件
try:
book = pyexcelerator.parse_xls(filepath, password=None)
return True
except:
# 尝试所有密码组合
for password in passwords:
try:
book = pyexcelerator.parse_xls(filepath, password=password)
return True
except:
pass
return False
# 测试密码
passwords = ['123456', '1', 'password']
if test_passwords(r'encrypted_file.xls', passwords):
print('正确的密码已找到')
else:
print('密码错误')