Unprotect an Excel file programmatically

后端 未结 4 833
我在风中等你
我在风中等你 2020-12-09 14:19

We\'re getting an Excel file from a client that has open protection and Write Reserve protection turned on. I want to remove the protection so I can open the Excel file wit

4条回答
  •  抹茶落季
    2020-12-09 15:16

    if you are on MacOS (or maybe Linux? not tested)

    You have to install Microsoft Excel and xlwings

    pip install xlwings

    Then run this:

    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
    

    Resources:

    • Adapted from this script: https://davidhamann.de/2018/02/21/read-password-protected-excel-files-into-pandas-dataframe/

    • xlwings documentation: https://docs.xlwings.org/en/stable/api.html

提交回复
热议问题