Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel File reading
#1
Hello, I am doing an assignment and not sure what im doing wrong. My job is to search the columns and rows of an excel file using openpxyl. So far I have got this code done.
import openpyxl

def functionOne ():
    print("Please enter the word you would like to find in the excel sheet.")
    userGuess = input()

    sampleWorkbook = openpyxl.load_workbook("c:\\Assignment.xlsx")
    sheet = sampleWorkbook.active

    for col in sheet.iter_cols(min_row=1, max_col=4, max_row=100):
        for cell in col:
            if userGuess == cell:
                print(cell)

functionOne ()
So, I need to output the column and row ID if the word was found in the list.
Each column has 100 words and there is 4 rows.

When I have entered a word that I know thats in the file I get nothing back.
I have tried replacing the part of the code:
if userGuess == cell:
print(cell)
with print (cell)
and I get the word that is in the file outputted back to me.

I'm new to programming so Im not sure what I'm doing wrong here.

Thanks.
Reply


Messages In This Thread
Excel File reading - by vanjoe198 - Mar-30-2021, 06:02 PM
RE: Excel File reading - by snippsat - Mar-31-2021, 11:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to convert .trc/.txt file into excel using python ebola 3 2,019 Jan-15-2023, 10:37 PM
Last Post: Yoriz
  reading from a file looseCannon101 14 4,917 Jul-18-2020, 11:29 AM
Last Post: GOTO10
  Weird problem with reading from file and performing calculations pineapple999 1 3,008 Jul-25-2019, 01:30 AM
Last Post: ichabod801
  Handling IO Error / Reading from file Expel 10 4,853 Jul-18-2019, 01:21 PM
Last Post: snippsat
  Reading an Unconventional CSV file OzSbk 2 3,885 May-17-2019, 12:15 PM
Last Post: MvGulik
  reading text file and writing to an output file precedded by line numbers kannan 7 10,413 Dec-11-2018, 02:19 PM
Last Post: ichabod801
  Read directly from excel file using python script dvldgs05 0 2,257 Oct-19-2018, 02:51 AM
Last Post: dvldgs05
  Reading of structured .mat (matlab) file sumit 2 3,423 May-24-2018, 12:12 PM
Last Post: sumit
  File Reading toxicxarrow 9 5,187 May-07-2018, 04:12 PM
Last Post: toxicxarrow
  reading all lines from a text file seadoofanatic 2 2,927 Mar-13-2018, 06:05 PM
Last Post: Narsimhachary

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020