I want to transfer my data which is in 'Sheet1' into worksheet 'Sheet2'in the same workbook, using python.I have written the script below, but facing an 'IndexError: list index out of range'. I know this is not the best way to go about it. I will appreciate if anyone can guide me with a more efficient way to go about it. I am sharing the Snapshot of excel file below
Can I directly enter 'Sheet1' cell value ---> 'Sheet2' cell value rather than doing 'Sheet1' cell value ---> List---->'Sheet2' cell value?
import openpyxl
wb = openpyxl.load_workbook('C:\Users\laban\Desktop\Par-emails1.xlsx')
type(wb)
wb.get_sheet_names()
sheet = wb.get_sheet_by_name('Sheet1')
type(sheet)
anotherSheet = wb.active
sheet1 = wb.get_sheet_by_name('Sheet2')
type(sheet1)
par=[sheet.cell(row= col, column=1).value for col in range(1, 2450)]
email_no=[sheet.cell(row= col, column=2).value for col in range(1, 2450)]
Domain=[sheet.cell(row= col, column=3).value for col in range(1, 2450)]
email=[sheet.cell(row= col, column=4).value for col in range(1, 2450)]
for x in range(0,2450):
if email_no[x]<9:
sheet1.cell(row= x+1, column=1).value=par[x]
sheet1.cell(row= x+1, column=2).value=email_no[x]
sheet1.cell(row= x+1, column=3).value=Domain[x]
sheet1.cell(row= x+1, column=4).value=email[x]
wb.save('C:\Users\laban\Desktop\Par-emails1.xlsx')
for x in range(0,2450)
? I remember openpyxl starts indexing at 1 instead of 0. – Elmex80sx = 0
at that line. Am I right? – Elmex80s