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