Skip to content

Instantly share code, notes, and snippets.

@dominiksimgen
Created January 29, 2021 22:20
Show Gist options
  • Save dominiksimgen/0037398cc88b39f8803516318c1ead71 to your computer and use it in GitHub Desktop.
Save dominiksimgen/0037398cc88b39f8803516318c1ead71 to your computer and use it in GitHub Desktop.
#https://stackoverflow.com/questions/27556751/unprotect-an-excel-file-programmatically
#Windows
def Remove_password_xlsx(filename, pw_str):
xcl = win32com.client.Dispatch("Excel.Application")
wb = xcl.Workbooks.Open(filename, False, False, None, pw_str)
xcl.DisplayAlerts = False
wb.SaveAs(filename, None, '', '')
xcl.Quit()
# macOS
import pandas as pd
import xlwings as xw
def _process(filename):
wb = xw.Book(filename)
sheet = wb.sheets[0]
df = sheet.used_range.options(pd.DataFrame, index=False, header=True).value
wb.close()
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment