關(guān)于excel密碼
有時(shí)我們?yōu)榱吮Wo(hù)Excel文檔,會(huì)給文檔加上密碼,如文檔查看、只讀密碼,工作表、工作簿的保護(hù)密碼等,但是時(shí)間久了難免忘記密碼,這時(shí)就只好進(jìn)行破解了。下面列舉幾種常用的破解Excel密碼的方法,供各位參考。
excel密碼的步驟:
首先我們要明確一個(gè)前提,不同類型的密碼,破解方法是不一樣的,有些密碼可能是無法破解的;而Excel文檔又分為不同版本(xls和xlsx),破解方法也有所不同。
溫馨提示:破解密碼前請(qǐng)先備份原文檔。
1、文檔查看、只讀密碼破解
Excel文檔的查看、只讀密碼目前沒有什么好的破解辦法,只能采用暴力破解,就是指定一個(gè)規(guī)則,然后一個(gè)一個(gè)去試。如果你當(dāng)初設(shè)置的密碼足夠復(fù)雜,那就不要做無所謂的掙扎了,建議及早放棄為好。但如果文檔十分重要,不計(jì)代價(jià)也要破解密碼,可以嘗試一些網(wǎng)站的收費(fèi)服務(wù),但是不要抱太高的希望。
2、工作表、工作簿的保護(hù)密碼
根據(jù)Excel文檔版本不同,工作表、工作簿保護(hù)密碼的破解方法也不太一樣。
(1)xls文檔破解方法
對(duì)于早期的xls文檔(2003及以前),可以用VBA代碼破解。
打開Excel文檔,按Alt+F11進(jìn)入“開發(fā)工具”界面,在左邊的工程欄(Project)中選定節(jié)點(diǎn)“ThisWorkbook”,雙擊左鍵,然后把下面的代碼復(fù)制到右邊的代碼編輯框中。然后按F5鍵執(zhí)行代碼開始破解,破解期間會(huì)出現(xiàn)兩次提示的對(duì)話框,都選擇“確認(rèn)”。密碼破解完畢之后會(huì)出現(xiàn)提示“該工作簿中的工作表密碼保護(hù)已被全部解除”,這說明工作表或工作簿的保護(hù)密碼已被成功清除。最后刪除“ThisWorkbook”節(jié)點(diǎn)中的代碼,保存工作表。至此,破解完成。
Public Sub 工作表保護(hù)密碼破解()
Const DBLSPACE As String = vbNewLine & vbNewLine
Const AUTHORS As String = DBLSPACE & vbNewLine & _
"作者:McCormick JE McGimpsey "
Const HEADER As String = "工作表保護(hù)密碼破解"
Const VERSION As String = DBLSPACE & "版本 Version 1.1.1"
Const REPBACK As String = DBLSPACE & ""
Const ZHENGLI As String = DBLSPACE & ""
Const ALLCLEAR As String = DBLSPACE & "該工作簿中的工作表密碼保護(hù)已全部解除!!" & DBLSPACE & "請(qǐng)記得另保存" _
& DBLSPACE & "注意:不要用在不當(dāng)?shù)胤?,要尊重他人的勞?dòng)成果!"
Const MSGNOPWORDS1 As String = "該文件工作表中沒有加密"
Const MSGNOPWORDS2 As String = "該文件工作表中沒有加密2"
Const MSGTAKETIME As String = "解密需花費(fèi)一定時(shí)間,請(qǐng)耐心等候!" & DBLSPACE & "按確定開始破解!"
Const MSGPWORDFOUND1 As String = "密碼重新組合為:" & DBLSPACE & "$$" & DBLSPACE & _
"如果該文件工作表有不同密碼,將搜索下一組密碼并修改清除"
Const MSGPWORDFOUND2 As String = "密碼重新組合為:" & DBLSPACE & "$$" & DBLSPACE & _
"如果該文件工作表有不同密碼,將搜索下一組密碼并解除"
Const MSGONLYONE As String = "確保為唯一的?"
Dim w1 As Worksheet, w2 As Worksheet
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer
Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer
Dim PWord1 As String
Dim ShTag As Boolean, WinTag As Boolean
Application.ScreenUpdating = False
With ActiveWorkbook
WinTag = .ProtectStructure Or .ProtectWindows
End With
ShTag = False
For Each w1 In Worksheets
ShTag = ShTag Or w1.ProtectContents
Next w1
If Not ShTag And Not WinTag Then
MsgBox MSGNOPWORDS1, vbInformation, HEADER
Exit Sub
End If
MsgBox MSGTAKETIME, vbInformation, HEADER
If Not WinTag Then
Else
On Error Resume Next
Do 'dummy do loop
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
With ActiveWorkbook
.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If .ProtectStructure = False And _
.ProtectWindows = False Then
PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
MsgBox Application.Substitute(MSGPWORDFOUND1, _
"$$", PWord1), vbInformation, HEADER
Exit Do 'Bypass all for...nexts
End If
End With
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
Loop Until True
On Error GoTo 0
End If
If WinTag And Not ShTag Then
MsgBox MSGONLYONE, vbInformation, HEADER
Exit Sub
End If
On Error Resume Next
For Each w1 In Worksheets
'Attempt clearance with PWord1
w1.Unprotect PWord1
Next w1
On Error GoTo 0
ShTag = False
For Each w1 In Worksheets
'Checks for all clear ShTag triggered to 1 if not.
ShTag = ShTag Or w1.ProtectContents
Next w1
If ShTag Then
For Each w1 In Worksheets
With w1
If .ProtectContents Then
On Error Resume Next
Do 'Dummy do loop
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If Not .ProtectContents Then
PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
MsgBox Application.Substitute(MSGPWORDFOUND2, _
"$$", PWord1), vbInformation, HEADER
'leverage finding Pword by trying on other sheets
For Each w2 In Worksheets
w2.Unprotect PWord1
Next w2
Exit Do 'Bypass all for...nexts
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
Loop Until True
On Error GoTo 0
End If
End With
Next w1
End If
MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK & ZHENGLI, vbInformation, HEADER
End Sub
(2)xlsx文檔破解方法
從2007版本以后,Excel文檔的擴(kuò)展名從xls變成了xlsx,文檔結(jié)構(gòu)也大變樣。Xlsx文檔本質(zhì)上其實(shí)是一個(gè)壓縮包,里面包含了許多xml文檔,工作表、工作簿的保護(hù)密碼就保存在這些xml文檔中,我們可以用WinRAR等壓縮工具將其解壓,然后直接修改內(nèi)容,就可以去掉工作表、工作簿的保護(hù)密碼了。
具體方法如下:
將文檔擴(kuò)展名修改為zip或rar,然后將其解壓。
在解壓得到的文件中找到“xl”文件夾,雙擊打開,“workbook.xml”中即包含工作簿的保護(hù)密碼,用記事本打開該文檔,搜索“workbookProtection”,將帶有“workbookProtection”的那一段代碼刪除即可。代碼格式如:
workbookProtection workbookAlgorithmName="SHA-512" workbookHashValue="******" workbookSaltValue="******" workbookSpinCount="100000" lockStructure="1"
另外,“xl\worksheets”文件夾下的“sheet1.xml”、“sheet2.xml”中則保存了各工作表的密碼,同樣用記事本打開,搜索“sheetProtection”,將帶有“sheetProtection”的那一段代碼刪除即可。
代碼格式如:
sheetProtection algorithmName="SHA-512" hashValue="******" saltValue="******" spinCount="100000" sheet="1" formatCells="0" formatColumns="0" formatRows="0" insertColumns="0" insertRows="0" insertHyperlinks="0" deleteColumns="0" deleteRows="0" sort="0" autoFilter="0" pivotTables="0"
最后保存文件,重新壓縮為zip格式(注意必須是zip,不能是rar或其他格式),然后把這個(gè)壓縮包的后綴重新修改回xlsx。至此,破解完成。
關(guān)于excel密碼相關(guān)文章: