admin管理员组文章数量:1130349
import os
import glob
import win32com.client as win32
#提示:
print("程序功能:批量对当前文件夹下的excel文件设置打开密码")
print("特别注意:请一定要记住自己设置的密码!!!")
print("吾爱:qzwsa 2023-03-18")
# 获取当前文件夹下所有Excel文件
excel_files = glob.glob(os.getcwd() + '\\*.xls*')
password = input('请输入密码,忘记没有解密:')
# 循环遍历Excel文件,并设置输入密码
for excel_file in excel_files:
if excel_file.endswith('.xlsx') or excel_file.endswith('.xls'):
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(excel_file)
try:
wb.Password = password
wb.Save()
wb.Close()
excel.Quit()
print('密码设置成功')
except:
print('密码设置失败请手动设置')在这里插入代码片
`
import os
import glob
import win32com.client as win32
#提示:
print("程序功能:批量对当前文件夹下的excel文件设置打开密码")
print("特别注意:请一定要记住自己设置的密码!!!")
print("吾爱:qzwsa 2023-03-18")
# 获取当前文件夹下所有Excel文件
excel_files = glob.glob(os.getcwd() + '\\*.xls*')
password = input('请输入密码,忘记没有解密:')
# 循环遍历Excel文件,并设置输入密码
for excel_file in excel_files:
if excel_file.endswith('.xlsx') or excel_file.endswith('.xls'):
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(excel_file)
try:
wb.Password = password
wb.Save()
wb.Close()
excel.Quit()
print('密码设置成功')
except:
print('密码设置失败请手动设置')在这里插入代码片
`
版权声明:本文标题:简约的批量对当前文件夹下的excel文件设置打开密码 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1763815637a2966100.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论