Python Forum
working with more excel files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
working with more excel files
#1
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'
Reply
#2
Shouldn't on row #5 be filename, not "*.xls"?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 346 Feb-07-2024, 12:24 PM
Last Post: Viento
  Working with Excel and Word, Several Questions Regarding Find and Replace Brandon_Pickert 4 1,492 Feb-11-2023, 03:59 PM
Last Post: Brandon_Pickert
  How to loop through all excel files and sheets in folder jadelola 1 4,329 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Creating csv files from Excel file azizrasul 40 5,326 Nov-03-2022, 08:33 PM
Last Post: azizrasul
  Working with excel files arsouzaesilva 6 3,093 Sep-17-2021, 06:52 PM
Last Post: arsouzaesilva
  win32com — How to resolve “AttributeError: xlUp” for Excel files? JaneTan 2 4,124 Aug-18-2021, 05:27 AM
Last Post: snippsat
Question Working with existing files Gilush 7 2,957 Feb-10-2021, 08:55 PM
Last Post: Gilush
  filecmp is not working for UTF-8 BOM encoded files sureshnagarajan 3 2,556 Feb-10-2021, 11:17 AM
Last Post: sureshnagarajan
  MP3 Tags to Excel Not working giddyhead 5 2,823 Jan-27-2021, 03:23 AM
Last Post: giddyhead
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,834 Dec-06-2020, 04:14 PM
Last Post: Divya577

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020