python - Excel File and Sheet Location -


i have list of excel files , corresponding sheet number. need python go sheets , find out cell location particular content. "alecxe", used following code , worked well.

import xlrd value = 'avg.' fn = ('c:/ab1.xls', 'c:/ab2.xls','c:/ab3.xls','c:/ab4.xls','c:/ab5.xls',) sn = ('505840', '505608', '430645', '505464', '505084') name, sheet_name in zip(fn, sn):     book = xlrd.open_workbook(name)     sheet = book.sheet_by_name(sheet_name)     row in range(sheet.nrows):         column in range(sheet.ncols):             if sheet.cell(row,column).value == value:                 print row, column 

later wanted make changes , instead of writing down filename , sheetnumber, wanted python grab them excel sheet. program not printing anything. can show me made mistake? highly appreciate comment!

import xlrd import glob import os value = 'avg.' sheetnumber = [] filename = [] xlfile = "c:\\users\\tsengineer\\desktop\\joydip trial\\simple.xls" workbook = xlrd.open_workbook(xlfile) sheet = workbook.sheet_by_index(0) row in range(sheet.nrows):     value = str(sheet.cell_value(row, 17))     filename.append(value) row in range(sheet.nrows):     value = str(sheet.cell_value(row, 15))     sheetnumber.append(value) fn = tuple(filename) sn = tuple(sheetnumber) name, sheet_name in zip(fn, sn):     book = xlrd.open_workbook(name)     sheet = book.sheet_by_name(sheet_name)     row in range(sheet.nrows):         column in range(sheet.ncols):             if sheet.cell(row,column).value == value:                 print row, column 

definitely reasons, loop not working getting 2 empty lists output. thoughts?

import xlrd value = 'avg.' sheetnumber = [] filename = [] rowlist = [] columnlist = [] xlfile = "c:/users/joyd/desktop/experiment/simple_1.xls" workbook = xlrd.open_workbook(xlfile) sheet = workbook.sheet_by_index(0) row in range(sheet.nrows):     value = str(sheet.cell_value(row, 17))     filename.append(value) row in range(sheet.nrows):     value = str(sheet.cell_value(row, 15))     sheetnumber.append(value) fn = tuple(filename) sn = tuple(sheetnumber) fname, sname in zip(fn, sn):     book = xlrd.open_workbook(fname)     sheet = book.sheet_by_name(sname)     row in range(sheet.nrows):         column in range(sheet.ncols):             if sheet.cell(row,column).value == value:                 rowlist.append(row)                 columnlist.append(column) print rowlist print columnlist 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -