如何打开受密码保护的excel文件并保存在数据帧中



我知道这个问题已经被问了很多次了,我已经通读了之前问的问题的答案,但我仍然不知道如何打开文件我想做的是,我在df中有一些数据,我想保存在现有的excel表df2中,它是密码处理的

df2 = pd.read_excel(r'C:UsersRTambe00000Desktoppython basicsweb scrapingIEDriverServer_Win32_4.0.0Data Miner Data.xlsx', sheet_name='data (1)')
df2 = df2.merge(df, left_on='Created', right_on ='Preferred Call Time')

我得到这个低于错误

XLRDError: Can't find workbook in OLE2 compound document

我已经解决了我的问题,并且能够打开受密码保护的excel文件。以下是我的代码:-


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()

最新更新