文章目录
一、EXCEL加密
python
import random
from win32com.client import Dispatch
def random_password(length=20):
'''默认返回20位随机密码'''
key = ""
characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
for i in range(length):
rand_char = random.choice(characters)
key += rand_char
return key
def excel_encryption(path, key):
'''excel加密'''
xcl = Dispatch("Excel.Application")
wb = xcl.Workbooks.Open(path)
xcl.DisplayAlerts = False
wb.SaveAs(path, Password=key)
xcl.Quit()
if __name__ == '__main__':
key = random_password(length=20)
print(key)
excel_encryption(path='', key=key)