python将Excel表格数据填充到Excel表单

安装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,可以检查文件是否有加密,把文件密码取消即可

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值