ezPyCrypto来encryptionMS Excel文件

我正尝试通过Python密码保护MS Excel文件。 到目前为止,我发现这不可能通过普通的Excel库(如openPyXL和XLSX Writer)来实现。

我想这意味着我首先需要encryption它。 如果我错了,或者如果有更好的方法,请纠正我。

密码保护位是最重要的,这在下面没有提到,除非很容易为此添加代码。

到目前为止,这里是我的encryption:

from ezPyCrypto import key file_in = r'P:\Data\sample_file.xlsx' file_out = file_in[:-5]+'_enc.xlsx' f_in = open(file_in, 'rb') f_out = open(file_out,'wb') in_str = f_in.read() out_str = key(in_str) f_out.write(out_str) f_in.close() f_out.close() 

但是,我不断收到这个错误:

 ImportError Traceback (most recent call last) <ipython-input-36-ed5218b0d47c> in <module>() 2 #https://github.com/sfbahr/PyCrypto-Wheels ----> 3 from ezPyCrypto import key 4 file_in = r'P:\Data\sample_file.xlsx' 5 file_out = file_in[:-5]+'_enc.xlsx' C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\ezPyCrypto.py in <module>() 70 from Crypto.Util.randpool import RandomPool 71 from Crypto.Util.number import getPrime ---> 72 from Crypto.Cipher import ARC2, Blowfish, CAST, DES3, IDEA, RC5 73 from Crypto.Hash import MD5 74 ImportError: cannot import name 'IDEA' 

我试图降级到早期版本的Crypto(回到1.0.0),但不断收到相同的错误,在Crypto.Cipher中寻找'IDEA'。

提前致谢!