Try the xlrd library.
From what I can see from your comment, something like the snippet below might do the trick. I’m assuming here that you’re just searching one column for the word ‘john’, but you could add more or make this into a more generic function.
from xlrd import open_workbook book = open_workbook('simple.xls',on_demand=True) for name in book.sheet_names(): if name.endswith('2'): sheet = book.sheet_by_name(name) # Attempt to find a matching row (search the first column for 'john') rowIndex = -1 for cell in sheet.col(0): # if 'john' in cell.value: break # If we found the row, print it if row != -1: cells = sheet.row(row) for cell in cells: print cell.value book.unload_sheet(name)
https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi
https://pypi.python.org/pypi/xlrd/0.6.1
xlrd description
Extract data from Excel spreadsheets (.xls and .xlsx, versions 2.0 onwards) on any platform. Pure Python (2.7, 3.4+). Strong support for Excel dates. Unicode-aware.
Working with Excel Files in Python
This site contains pointers to the best information available about working with Excel files in the Python programming language. The PackagesThere are python packages available to work with Excel files that will run on any Python platform and that do not require either Windows or Excel to be used. They are fast, reliable and open source:
openpyxlThe recommended package for reading and writing Excel 2010 files (ie: .xlsx)
xlsxwriterAn alternative package for writing data, formatting information and, in particular, charts in the Excel 2010 format (ie: .xlsx)
Download | Documentation | GitHubxlrdThis package is for reading data and formatting information from older Excel files (ie: .xls)
xlwtThis package is for writing data and formatting information to older Excel files (ie: .xls)
xlutilsThis package collects utilities that require both xlrd and xlwt, including the ability to copy and modify or filter existing excel files.
NB: In general, these use cases are now covered by openpyxl!
|