-
-
Save nguyenhx2/e746bc204ba6832116d76f78aae7618c to your computer and use it in GitHub Desktop.
Unlock Excel Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Attribute VB_Name = "PasswordBreaker" | |
Sub PasswordBreaker() | |
'Breaks worksheet password protection. | |
Dim a As Integer, b As Integer, c As Integer, d As Integer, e As Integer, f As Integer | |
Dim g As Integer, h As Integer, i As Integer, j As Integer, k As Integer, l As Integer | |
On Error Resume Next | |
For a = 65 To 66: For b = 65 To 66: For c = 65 To 66: For d = 65 To 66: For e = 65 To 66: For f = 65 To 66 | |
For g = 65 To 66: For h = 65 To 66: For i = 65 To 66: For j = 65 To 66: For k = 65 To 66: For l = 32 To 126 | |
ActiveSheet.Unprotect Chr(a) & Chr(b) & Chr(c) & Chr(d) & Chr(e) & Chr(f) & Chr(g) & Chr(h) & Chr(i) & Chr(j) & Chr(k) & Chr(l) | |
If ActiveSheet.ProtectContents = False Then | |
degub.Print "pw: " & Chr(a) & Chr(b) & Chr(c) & Chr(d) & Chr(e) & Chr(f) & Chr(g) & Chr(h) & Chr(i) & Chr(j) & Chr(k) & Chr(l) | |
Exit Sub | |
End If | |
Next: Next: Next: Next: Next: Next: Next: Next: Next: Next: Next: Next | |
End Sub | |
Sub PasswordBreakAllSheets() | |
'Loops through all sheets and breaks worksheet password protection | |
Dim wb As Workbook: Set wb = ActiveWorkbook | |
Dim ws As Worksheet | |
For Each ws In wb.Worksheets | |
ws.Activate | |
PasswordBreaker | |
Next | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This will have issues if there are spaces in the file name. To replace the spaces with underscores, run: | |
## find -name "* *" -type f | rename 's/ /_/g' | |
# If this file is saved in your path as unlockxl, you can loop through all files in your directory with | |
## for i in ./*.xls*; do unlockxl.sh "$i"; done | |
# Parse out file name and extension | |
filename=$(basename "$1") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
# Determine if the file is an excel file | |
xlfile=0 | |
if [ $extension == "xls" ]; then | |
xlfile=1 | |
elif [ $extension == "xlsx" ]; then | |
xlfile=1 | |
fi | |
# Quit if not an excel file | |
if [ $xlfile -eq 0 ]; then | |
echo "That's not an excel file, must be: .xls, .xlsx" | |
exit 0 | |
fi | |
# Convert to 2007 format if .xls | |
if [ $extension == "xls" ]; then | |
echo "Converting from .xls to .xlsx" | |
libreoffice --convert-to xlsx $filename".xls" --headless | |
fi | |
echo "Moving .xlxs to .zip" | |
mv $filename".xlsx" $filename".zip" | |
echo "Unzipping .zip file" | |
unzip $filename".zip" | |
echo "Deleting the .zip file" | |
rm $filename".zip" | |
# Where the magic happens | |
echo "Removing workbook passwords" | |
sed -i 's/<workbookProtection[^>]*>//' xl/workbook.xml | |
echo "Removing worksheet passwords" | |
sed -i 's/<sheetProtection[^>]*>//' xl/worksheets/*.xml | |
echo "Ensuring all sheets are visible" | |
sed -i 's/state="hidden"/state="visible"/g' xl/workbook.xml | |
# Cleaning up | |
echo "Rezipping excel parts" | |
zip -r $filename".zip" \[Content_Types\].xml docProps/ _rels/ xl/ | |
echo "Cleanup the trash" | |
rm -R \[Content_Types\].xml docProps/ _rels/ xl/ | |
echo "Moving .zip back to .xlsx" | |
mv $filename".zip" $filename".xlsx" | |
echo "Done" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment