日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

两种方法清除Excel保护密码

發(fā)布時(shí)間:2023/12/4 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 两种方法清除Excel保护密码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、利用VBA腳本直接清除

打Excel,打開腳本編輯器(Alt+F11)或者如圖,右鍵sheet名稱

輸入代碼并運(yùn)行,即可清除密碼保護(hù):

Sub DeletePW()ActiveSheet.Protect DrawingObjects:=True, Contents:=True, AllowFiltering:=TrueActiveSheet.Protect DrawingObjects:=False, Contents:=True, AllowFiltering:=TrueActiveSheet.Protect DrawingObjects:=True, Contents:=True, AllowFiltering:=TrueActiveSheet.Protect DrawingObjects:=False, Contents:=True, AllowFiltering:=TrueActiveSheet.Unprotect End Sub

二、用python代碼批量處理多個(gè)Excel文件?

注意:這種方法前提是得知道密碼。

直接上代碼:

''' Title: 批量清除Excel保護(hù)密碼 Author: JackieZheng Date: 2022-04-07 20:38:46 LastEditTime: 2022-04-08 18:35:37 LastEditors: Please set LastEditors Description: FilePath: \\pythonCode\\RemoveExcelPwd.py '''import os import win32com.client from win32com.client import Dispatch# 如果有打開的excel窗口先關(guān)閉,否則后邊會(huì)報(bào)錯(cuò) def removePassword(path,password):try:xlApp = win32com.client.DispatchEx('Excel.Application')except Exception as err:print('錯(cuò)誤: %s' % err)try:for file in os.listdir(path):filepath = os.path.join(path, file)if not os.path.isfile(filepath):continueprint(filepath)xlApp.Visible = FalsexlApp.DisplayAlerts = Falsewb = xlApp.Workbooks.Open(filepath)try:# print(password)wb.Unprotect(password)wb.Checkcompatibility = Falsesht = wb.Worksheets('Sheet1')sht.Unprotect(password)except Exception as err:print('清除 %s 的保護(hù)密碼出錯(cuò):%s' % (file, err))wb.Save()wb.Close(SaveChanges=True)finally:if hasattr(xlApp, 'Quit'):xlApp.Quit()path=r'E:\數(shù)據(jù)\2021院校專業(yè)計(jì)劃' password=r'135246' removePassword(path,password)

總結(jié)

以上是生活随笔為你收集整理的两种方法清除Excel保护密码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。