Aug-18-2021, 06:25 PM
Hello everybody. I'm new here and new one in Python. I have such piece of code and I don't know how to understand some parts of it.
Could you please help me?
Could you please help me?
from openpyxl import load_workbook, Workbook
def reader(file_name, search_string1, search_string2): #this is our file read function with 2 search words
book = load_workbook(file_name, read_only=True) #this is how we open it
items = [ # Here I need help I don't know what is going on here. We have some list(items = [])
(o.value, ) # What is this?
for i in book.active.iter_rows() #Here we are going over sheet
for o in i #Here we are goking over lines
if o.value and isinstance(o.value, str) #Here we compare our words with cell data
and search_string1.lower() in o.value.lower() and search_string2.lower() in o.value.lower() #Could anybody describe this block of code in more detail
] #Or write this piece of code for newbie language
return items
def writer(items):
book = Workbook()
sheet = book.active
for row in items:
sheet.append(row)
book.save('result.xlsx')
if __name__ == '__main__':
items = reader("WEG.xlsx", '5g10', 'xpj')
writer(items)
