主要应用python3+tkinter
功能:批量加密和解密主流的表格及文档文件(如et、xls、xlsx、wps、doc、docx等)。
接口库:win32com
#程序运行前,请提前关闭WPS文件def is_wps(self):wpspids = pids()for pid in wpspids:#try:p = Process(pid)if p.name() == et.exe or p.name() == wps.exe or p.name() == wpspdf.exe:return True#中止进程 def killpid(self):wpspids = pids()for pid in wpspids:try:p = Process(pid)if p.name() == et.exe or p.name() == wps.exe or p.name() == wpspdf.exe:p.kill()except:pass
#打开WPS文件def openwps(self,isxls):if isxls == xls:ecl = client.Dispatch("Ket.Application")elif isxls == doc:ecl = client.Dispatch("Kwps.Application")ecl.Visible = False # 可视化ecl.DisplayAlerts = False # 是否显示警告return ecl
#设置密码def pwd_xlsx(self,new_filename,pwd_str,excel): try: wb = excel.Workbooks.Open(new_filename, UpdateLinks=False, ReadOnly=False, Format=None, Password=) wb.SaveAs(new_filename, None, pwd_str, ) time.sleep(0.01) #关键wb.Close(SaveChanges=True)return Trueexcept:return False
#主程序段加密WPS文件,pwd为密码、efiles为文件列表,is_pwd()为判断是否已加密def jmwps(self, pwd, efiles):v = messbox.askyesno(title=确定,message=请确认是否继续完成文件加密操作?)if v == 1:if len(efiles)>0 :excel = self.openwps(xls)excel.EnableEvents = False for xls_name in efiles: if not self.is_pwd(xls_name,xls,excel):try:if self.pwd_xlsx(xls_name, pwd,excel):i += 1 except:continueexcel.EnableEvents = Trueexcel.Quit()time.sleep(0.1)try:self.killpid()except:pass ......