0
votes
from openpyxl import load_workbook


    wb=load_workbook('Project_Python.xlsx')
    sheet2=wb.get_sheet_by_name('Sheet2')
    sheet3=wb.get_sheet_by_name('Sheet3')


    sheet1=wb.get_sheet_by_name('Sheet1')
    sheet3=wb.get_active_sheet()


    for i in range(3,6369):
        d1=(sheet1.cell(row=i,column=1).value)
        for j in range(3,6369):
            d2=(sheet2.cell(row=i,column=1).value)
        if d1==d2:
            print(i,sheet1.cell(row=i,column=1).value,"same")
        else:
            print(i,sheet2.cell(row=i,column=1).value,"modified")

I was comparing two excel sheets i.e sheet1 and sheet2 and i want to display the last 2 outputs in my sheet3 on same workbook. How can i do that?

1
This looks like a rather inefficient way to do things because it uses a nested loop. You should look at using zip and ws.get_squared_range as an alternative.Charlie Clark

1 Answers

0
votes

To write in a cell:

sheet3.cell(column=1, row=1, value="SOMETHING")

Put it where you want .