Link to home
Start Free TrialLog in
Avatar of Parker Robertson
Parker Robertson

asked on

Is it possible to search for specific data in an Excel Document?

I'm currently trying to create a script that will search for specific data in an excel document and print out a range of cells.

For example, it would search for "color" in column A. If "color" was found in A4 it would print out the data in A4, B4, C4, D4, etc.

import openpyxl
wb = openpyxl.load_workbook('example.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')

for rowOfCellObjects in sheet['A1':'C3']:
    for cellObj in rowOfCellObjects:
        print(cellObj.coordinate, cellObj.value)

Open in new window


This is the only code I have so far which is an excerpt from Al Sweigart. “Automate the Boring Stuff with Python: Practical Programming for Total Beginners.” iBooks. and the only thing it does is search for specific cell addresses and prints those.

Is this a feasible project? I'm very new to Python so I don't fully grasp its limitations.

Any help would be appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Parker Robertson
Parker Robertson

ASKER

Thanks for the help, but I've still got a few questions.
  1. I'm trying to specifically find values in column "I" and print every corresponding cell in E, F, G, H, and I for the row it was found on
  2. The sheet that I would be searching is Sheet2 titled "Details" instead of Sheet1
  3. I would like to print all of the output to a separate word or excel document.

What changes to the code should I make in order to accomplish these goals?