Python Forum

Full Version: working with more excel files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I would like to modify my existing code that extracts the value of some cells. How can I modify it to do it not only one but for more xls, that are in the same directory.
I tried something like this:

 import xlrd
    import glob
    for filename in glob.glob('*.xls'):
    
        book = xlrd.open_workbook("*.xls", formatting_info=True)
        sheets = book.sheet_names()
    
        for index, sh in enumerate(sheets):
            sheet = book.sheet_by_index(index)
            #print "Sheet:", sheet.name
            rows, cols = sheet.nrows, sheet.ncols
            #print "Number of rows: %s   Number of cols: %s" % (rows, cols)
    
            for row in range(rows):
                for col in range(cols): ....
the error is
Quote:IOError: [Errno 22] invalid mode ('rb') or filename: '*.xls'
Shouldn't on row #5 be filename, not "*.xls"?