'how to open passward protected excel file and save in dataframe

i know this question has been asked many times , i have read through the answers of previously asked question however im still not getting how to open the file what i want to do is i have some data in df that i want to save in the existing excel sheet df2 which is password procted

df2 = pd.read_excel(r'C:\Users\RTambe00000\Desktop\python basics\web scraping\IEDriverServer_Win32_4.0.0\Data Miner Data.xlsx', sheet_name='data (1)')

df2 = df2.merge(df, left_on='Created', right_on ='Preferred Call Time')

im getting this below error

XLRDError: Can't find workbook in OLE2 compound document



Solution 1:[1]

i have solved my issue and was able to open the password protected excel file. Below is my code:-


import win32com.client

xl = win32com.client.gencache.EnsureDispatch('Excel.Application')
wb = xl.Workbooks.Open('File path', False, False, None, 'Read passward','Edit passward')
xl.Visible=1
time.sleep(5)
# to refresh the file 
wb.RefreshAll()
time.sleep(5)
wb.Save()

xl.Quit()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rohan tambe