0

I am looking for help, how to check if my excel (.xl*) file is protected by password or not(I do not mean sheet_protection but whole file (work_book).

I was thinking about using vba by xlwings.api to do that, but can't figure out how to do that. I found vba code for that here: https://www.thespreadsheetguru.com/the-code-vault/2014/12/17/determine-if-workbook-or-worksheet-is-password-protected-with-excel-vba?rq=password

Any ideas?

Piotr Kotarba
  • 25
  • 1
  • 6
  • 1
    Please check [here](https://stackoverflow.com/questions/54558302/how-to-check-if-a-large-excel-file-is-protected-as-fast-as-possible) as it seems already answered. – Svestis Feb 20 '20 at 17:15
  • Unfortunately solutions from there are not working. I want to avoid situation where exception inform me about password protection. – Piotr Kotarba Feb 21 '20 at 06:25

1 Answers1

0
wb = openpyxl.load_workbook("Workbook.xlsx")

print(wb.protection.workbook_password)

it will return None if there is no password else something like a key but not the password

Manish Chaudhary
  • 498
  • 6
  • 14
  • if you're looking to remove password from your excel file then this code might help you if all files have a same file then use it in loop else do it separately. #def Remove_password_xlsx(filename, password): $ xcl = win32com.client.Dispatch("Excel.Application") $ wb = xcl.Workbooks.Open(filename, False, False, None, password) $ xcl.DisplayAlerts = False $ wb.SaveAs(filename, None, '', '') $xcl.Quit() – Manish Chaudhary Feb 26 '20 at 07:05
  • I know how to open password protected excel, how to save it without password. I am looking for function/method to check if my excel is password protected. I want to avoid using try/except clause, because accidentally it may catch something else than password protected excel. – Piotr Kotarba Feb 26 '20 at 10:48