openpyxl将整个行复制并粘贴到for循环中

时间:2018-12-21 15:30:39

标签: python openpyxl

如何在for循环中将整行复制并粘贴到另一个工作表中。在每次迭代中,复制到接收工作表中的数据都不应被覆盖。下面是尝试。

wb = openpyxl.load_workbook(excel_file)

sheet1 = wb["sheet1"]
sheet2 = wb["sheet2"]


lrow_sheet1 = len(sheet1['A'])
lrow_sheet2= len(sheet2['A'])

for i in range(2, lrow_sheet1):
    inv_no_sheet1 = sheet1.cell(row = i, column = 1).value
    for j in range(2, lrow_sheet2):
    inv_no_sheet2 = sheet2.cell(row = j, column = 1).value
        if inv_no_sheet2 == inv_no_sheet1:
            # copy current entire row in sheet1 and paste to sheet3
            # copy current entire row in sheet2 and paste to sheet4

0 个答案:

没有答案