0

I am trying to iterate through a folder containing about 5 files (this will continue to increase each month). Presently the files which are xlsx files are password protected. I need to read the contents of these files into my pandas dataframe. Currently, when I try the following code I get the error message: XLRDError: Can't find workbook in OLE2 compound document

I am trying to find an approach which does not require manual intervention with the password potentially baked in. I saw some examples of code online referring to the win32 library but couldn't find one that involved both win32 and pandas.

from glob import glob
import os

monthly_cvr_root = glob("C:/path_to_files/*.xlsx")

df3 = pd.DataFrame()

for files in monthly_cvr_root:
    data = pd.read_excel(files, header=None)
    data['EffectiveDate'] = os.path.basename(files)[11:19]
    df3 = df3.append(data)
    
df3


Any help is appreciated. Thanks!

BJD
  • 49
  • 9
  • Does this answer your question? [How to open a password protected excel file using python?](https://stackoverflow.com/questions/19450837/how-to-open-a-password-protected-excel-file-using-python) – Keiron Stoddart Aug 19 '21 at 20:00
  • I’m expecting to still leverage the password (I know the password) but am trying to find a way of baking it into the code. I will look into the post you shared @KeironStoddart – BJD Aug 19 '21 at 21:01

0 Answers0