安装load_workbook第三方库
from openpyxl import load_workbook
import glob
# 加载源文件和目标文件
source_wb = load_workbook(r'C:\Users\HP08\Desktop\123\附件3:xxx.xlsx')
target_wb = load_workbook(r'C:\Users\HP08\Desktop\123\附件2:xxx.xlsx')
# 选择源文件中的工作表和目标文件中的工作表
source_ws = source_wb['Sheet1']
target_ws = target_wb['Sheet1']
# 提取数据并放入目标单元格
for i in range(4,22):
i = str(i)
# 源数据单元格
# print("已经完成",i)
data1 = source_ws['A'+i].value
# 目标单元格
target_ws['B4'] = data1
data2 = source_ws['B'+i].value
target_ws['D4'] = data2
data3 = source_ws['C'+i].value
target_ws['F4'] = data3
data4 = source_ws['E'+i].value
target_ws['K4'] = data4
data5 = source_ws['G'+i].value
target_ws['B5'] = data5
data6 = source_ws['H'+i].value
target_ws['E5'] = data6
data7 = source_ws['D'+i].value
target_ws['K5'] = data7
data8 = source_ws['F'+i].value
target_ws['B6'] = data8
data9 = source_ws['J'+i].value
target_ws['K6'] = data9
data10 = source_ws['N'+i].value
target_ws['B7'] = data10
data11 = source_ws['I'+i].value
target_ws['H7'] = data11
data12 = source_ws['K'+i].value
target_ws['H8'] = data12
data13 = source_ws['O'+i].value
target_ws['B10'] = data13
data14 = source_ws['P'+i].value
target_ws['G10'] = data14
data15 = source_ws['Q'+i].value
target_ws['K10'] = data15
data16 = source_ws['R'+i].value
target_ws['B11'] = data16
data17 = source_ws['S'+i].value
target_ws['G11'] = data17
data18 = source_ws['T'+i].value
target_ws['B12'] = data18
data19 = source_ws['U'+i].value
target_ws['K12'] = data19
data20 = source_ws['V'+i].value
target_ws['C13'] = data20
data21 = source_ws['W'+i].value
target_ws['G13'] = data21
data22 = source_ws['X'+i].value
target_ws['D14'] = data22
data23 = source_ws['Y'+i].value
target_ws['D15'] = data23
data24 = source_ws['AI'+i].value
target_ws['B17'] = data24
data25 = source_ws['AJ'+i].value
target_ws['F17'] = data25
data26 = source_ws['AK'+i].value
target_ws['B18'] = data26
data27 = source_ws['AL'+i].value
target_ws['F18'] = data27
data28 = source_ws['Z'+i].value
target_ws['B24'] = data28
data29 = source_ws['AA'+i].value
target_ws['E24'] = data29
data30 = source_ws['AB'+i].value
target_ws['B25'] = data30
data31 = source_ws['AC'+i].value
target_ws['E25'] = data31
data32 = source_ws['AD'+i].value
target_ws['G24'] = data32
data33 = source_ws['AE'+i].value
target_ws['K24'] = data33
data34 = source_ws['AF'+i].value
target_ws['G25'] = data34
data35 = source_ws['AG'+i].value
target_ws['K25'] = data35
data36 = source_ws['L'+i].value
target_ws['F6'] = data36
data37 = source_ws['M'+i].value
target_ws['B8'] = data37
# 保存目标文件
target_wb.save(r"C:\Users\HP08\Desktop\123"+"\\"+i+".xlsx")
target_wb.close()
# 如果编译运行后显示文件不是zip,可以检查文件是否有加密,把文件密码取消即可