Python 如何使用openpyxl在特定单元格中粘贴?

Python 如何使用openpyxl在特定单元格中粘贴?,python,openpyxl,Python,Openpyxl,我想选择一系列单元格,从源excel到目标excel。通过下面的代码,我成功地做到了这一点(我需要从E6:E15中提取数据)。但是,数据也会粘贴到目标工作簿中的单元格E6:E15中 我如何进入不同的牢房?例如F6:F15 代码: 作品谢谢你的作品!非常感谢。 import openpyxl wbo = openpyxl.load_workbook(r'file_origin.xlsx', read_only=True) wbd = openpyxl.load_workbook(r'file_d

我想选择一系列单元格,从源excel到目标excel。通过下面的代码,我成功地做到了这一点(我需要从E6:E15中提取数据)。但是,数据也会粘贴到目标工作簿中的单元格E6:E15中

我如何进入不同的牢房?例如F6:F15

代码:


作品谢谢你的作品!非常感谢。
import openpyxl

wbo = openpyxl.load_workbook(r'file_origin.xlsx', read_only=True)
wbd = openpyxl.load_workbook(r'file_destination.xlsx')

wso= wb['Sheet1']
wsd= wb1['Sheet1']

for row in wso['E6':'E15']:
    for cell in row:
        wsd[cell.coordinate].value = cell.value
import openpyxl

wbo = openpyxl.load_workbook(r'file_origin.xlsx', read_only=True)
wbd = openpyxl.load_workbook(r'file_destination.xlsx')

#attach the ranges to the workbooks
wso= wbo['Sheet1']['E6':'E15']
wsd= wbd['Sheet1']['F6':'F15']

#step1 : pair the rows
#since it is the same number of rows 
#row 6 will pair with 6, 7 with 7  ,....
for row1,row2 in zip(wso,wsd):
    #within the row pair, pair the cells
    for cell1, cell2 in zip(row1,row2):
        #assign the value of cell 1 to the destination cell 2 for each row
        cell2.value = cell1.value
#save document
wbd.save('destination.xlsx')