[python-win32] exception while opening excel file

iceblink at chello.nl iceblink at chello.nl
Wed Apr 16 09:37:19 CEST 2008


---- Mark Hammond <mhammond at skippinet.com.au> schreef:
> > > Normally I can just press "close" in the excel error box, and
> > continue
> > > to work on the file. But how do I handle this in py-win32?
> > 
> > So what happens when you try to open it normally?
> 
> Oops - sorry - I see you already gave the exception you get trying to open
> the file.  I'm afraid I don't know the answer though.
> 

In answer to my own question, the following code seems to work:

xlApp = Dispatch("Excel.Application")
wb1=xlApp.Workbooks.Open(inputfile,ReadOnly=1,CorruptLoad=1)
xlApp.SendKeys("{Enter}",Wait=1)
xlApp.DisplayAlerts = 0
xlApp.Quit()
del xlApp

The trick was to find the right CorruptLoad statement and corresponding number for "xlRepairFile".

The DisplayAlerts is needed to prevent Excel from asking if it should save a file that was opened as ReadOnly in the first place... hmmmm.

Best regards,

Patrick Asselman


More information about the python-win32 mailing list