Python/excel - Ioerror: [errno 2] No Such File Or Directory:
Attempting to extract .xlsx docs from a file and compile the data into a single worksheet. Receiving a IOError despite that the files exist Program is as follows #-------------- lo
Solution 1:
You are opening the plain filename without the path; you are ignoring the directory component.
Don't just print the os.path.join()
result, actually use it:
filename = os.path.join(subdir, file)
r = xlrd.open_workbook(filename)
Solution 2:
For the first problem...
Instead of:
r = xlrd.open_workbook(file)
Use:
r = xlrd.open_workbook(os.path.join(subdir,file))
For the TypeError: Instead of:
for sheet in r:
if sheet.number_of_rows()>0:
count += 1
Use:
for nsheet in r.sheet_names() #you need a list of sheet names to loop throug
sheet = r.sheet_by_name(nsheet) #then you create a sheet object with each name in the listif sheet.nrows>0: #use the property nrows of the sheet object to count the number of rows
count += 1
Do the same for the second for loop.
Post a Comment for "Python/excel - Ioerror: [errno 2] No Such File Or Directory:"