python制作合同模板带图片_python生成各类合同

安装包

pip install  python_docx

pip install xlrd

代码示例

from docx import Document

import xlrd

def change_text(old_text,new_text):#

#读取文章中所有段落列表

all_paras= document.paragraphs

for run in all_paras:

run_text=run.text.replace(old_text,new_text)

run.text=run_text

all_tables=document.tables

for tabel in all_tables:

for row in tabel.row:

for cell in row.cells:

cell_text=cell_text.replace(old_text,new_text)

cell.text=cell_text

xlsx=xlrd.open_workbook('C://Users//fuxingyu//Desktop//hetong//信息.xlsx')

sheet=xlsx.sheet_by_index(0)

for table_row in range(1,sheet.nrows):

document=Document("C://Users//fuxingyu//Desktop//hetong//合同.docx")

for tabel_col in range(0,sheet.ncols):

change_text(str(sheet.cell_value(0,tabel_col)),str(sheet.cell_value(table_row,tabel_col)))

document.save("C://Users//fuxingyu//Desktop//hetong//%s合同.docx"%str(sheet.cell_value(table_row,0)))

print("%s合同完成"%str(sheet.cell_value(table_row,0)))

效果

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值