Question

Is there a way to handle xlrd errors in the program? I have a complex problem with thousands of excel files. I am trying to parse the list of files, open each spreadsheet and determine if the spreadsheet has a specific tab or sheet. Create a new list of the files with the matching sheet name. However, I keep getting dropped out due to errors. First was ragged, turned out to be a file with multiple periods (ie. Myfile.New.Jan2013.xls). I temporarily renamed that one and but now it dropped out - Workbook is encrypted. I have no control over the files - they were supplied to me. And there are far too many to go through one at a time and change. So I would like to just skip or create a list of the files that are faulty and continue with my loop. I have been googling, but have not found anything on error handling within xlrd yet. Any suggestions?

Thanks!

Was it helpful?

Solution

without having more information all I can do is suggest a general

exceptions = []

for excel_file in excel_file_list:
    try:
        some_things
    except Exception, e:
       exceptions.append((excel_file,e.message))

This modification will tell you what the problem was for each file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top