简体   繁体   中英

Error trying to read blockede xls file on python

I am trying to open an Xls file on using python pandas ( also tried several others libraries like xlrd and pyexcel) and wasnt able to open it. when a try to used the comand

df = pd.read_excel('mil.xls')

I get following error:

_locate_stream(Workbook): seen 0 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 20 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 40 2

I found out that when, before trying to read it, I unblock the file, that is, disable manually the protected view mode on excel, I could read the file normally. Is there a way I can unblock the .Xls file on python though some librarie ?

I've noted that if you open and save the file you can read it. This piece of code solve the problem:

xcl = win32com.client.Dispatch('Excel.Application')
wb = xcl.workbooks.open(filename)
xcl.DisplayAlerts = False
wb.Save()
xcl.Quit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM