title: Python - program for searching for relevant cells in excel does not work correctly
body: <p>I've written a code to search for relevant cells in an excel file. However, it does not work as well as I had hoped.
  In pseudocode, this is it what it should do:</p>
  
  <pre><code>Ask for input excel file
  Ask for input textfile containing keywords to search for
  Convert input textfile to list containing keywords
  For each keyword in list, scan the excelfile
  If the keyword is found within a cell, write it into a new excelfile
  Repeat with next word
  </code></pre>
  
  <p>The code works, but some keywords are not found while they are present within the input excelfile. I think it might have something to do with the way I iterate over the list, since when I provide a single keyword to search for, it works correctly. This is my whole code: <a href="https://pastebin.com/euZzN3T3" rel="nofollow noreferrer">https://pastebin.com/euZzN3T3</a></p>
  
  <p>This is the part I suspect is not working correctly. Splitting the textfile into a list works fine (I think).</p>
  
  <pre><code>#IF TEXTFILE
  elif btext == True:
      #Split each line of textfile into a list
      file = open(txtfile, 'r')
      #Keywords in list
      for line in file:          
          keywordlist = file.read().splitlines()
      nkeywords = len(keywordlist)    
      print(keywordlist)
      print(nkeywords)
  
      #Iterate over each string in list, look for match in .xlsx file
      for i in range(1, nkeywords):
          nfound = 0
          ws_matches.cell(row = 1, column = i).value = str.lower(keywordlist[i-1])
          for j in range(1, worksheet.max_row + 1):
              cursor = worksheet.cell(row = j, column = c)
              cellcontent = str.lower(cursor.value)
              if match(keywordlist[i-1], cellcontent) == True:
                  ws_matches.cell(row = 2 + nfound, column = i).value = cellcontent
                  nfound = nfound + 1     
  </code></pre>
  
  <p>and my <code>match()</code> function:</p>
  
  <pre><code>def match(keyword, content):
  """Check if the keyword is present within the cell content, return True if found, else False"""
  if content.find(keyword) == -1:
      return False
  else:
      return True
  </code></pre>
  
  <p>I'm new to Python so my apologies if the way I code looks like a warzone. Can someone help me see what I'm doing wrong (or could be doing better?)? Thank you for taking the time!</p>