Python - Extracting excel docs from file, need help reading data
Question: So I've been working on a project extracting .xlsx docs from a file in attempt
to compile the data into one worksheet.

So for I've managed a loop to pull the documents but now I'm stuck trying to
read the documents.

Python 2.7

As follows, my script and response in the shell

    
    
    #-------------- loop that pulls in files from folder--------------
    import os
    
    #create directory from which to pull the files
    rootdir = 'C:\Users\username\Desktop\Mults'
    
    for subdir, dir, files in os.walk(rootdir):
    for file in files:
        print os.path.join(subdir,file)
    #----------------------merge work books-----------------------
    
    import xlrd
    import xlsxwriter
    
    
    wb = xlsxwriter.workbook('merged.xls')
    ws = workbook.add_worksheet()
    for file in filelist:
        r = xlrd.open_workbook(file)
        head, tail = os.path.split(file)
        count = 0
        for sheet in r:
            if sheet.number_of_rows()>0:
                count += 1
        for sheet in r:
            if sheet.number_of_rosw()>0:
                if count == 1:
                    sheet_name = tail
                else:
                    sheet_name = "%s_%s" (tail, sheet.name)
                new_sheet = wb.create_sheet(sheet_name)
                new_sheet.write_reader(sheet)
                new_sheet.close()
    wb.close()
    

The error I'm receiving when I run the program

    
    
    C:\Users\username\Desktop\Mults\doc1.xlsx
    C:\Users\username\Desktop\Mults\doc2.xlsx
    C:\Users\username\Desktop\Mults\doc3.xlsx
    C:\Users\username\Desktop\Mults\doc4.xlsx
    
    Traceback (most recent call last):
      File "C:\Users\username\Desktop\Work\Python\excel practice\xlsx - loops files 
    - 09204.py", line 20, in <module>
    wb = xlsxwriter.workbook('merged.xls')
    TypeError: 'module' object is not callable
    

I know I'm missing a step somewhere to connect the data.

I've practiced with xlsxwriter in other scripts and the module worked fine.
For some reason won't recognize it here.

Also, as suggested I've tried xlwt, but experienced trouble importing the
module into my shell even though it is installed accordingly.

Any tips will be helpful!

Thanks!


Answer: It is a capital `W` in `WorkBook`

    
    
     wb = xlsxwriter.Workbook('merged.xls')
    

You should also use `/` slashes or `r` raw string in paths in windows:

    
    
    r'C:\Users\username\Desktop\Mults'
    
    'C:/Users/username/Desktop/Mults'
    

`ws = workbook.add_worksheet()` will also cause an error as `workbook` is not
defined anywhere.

I think you mean `wb.add_worksheet()`

