首页 > 其他 > 详细

批量生成n份不同的乙方合同

时间:2020-02-21 21:46:56      阅读:162      评论:0      收藏:0      [点我收藏+]

from docx import Document
import xlrd

def change_text(old_text,new_text):
    all_paragraphs = document.paragraphs
    for paragraph in all_paragraphs:
        for run in paragraph.runs:
            run_text = run.text.replace(old_text,new_text)
            run.text = run_text
            
    all_tables = document.tables
    for table in all_tables:
        for row in table.rows:
            for cell in row.cells:
                cell_text = cell.text.replace(old_text,new_text)
                cell.text = cell_text
                
xlsx = xlrd.open_workbook(r‘C:\Users\13375\Desktop\python\合同信息表.xlsx‘)
sheet = xlsx.sheet_by_index(0)

for table_row in range(1,sheet.nrows):
    document = Document(r‘C:\Users\13375\Desktop\python\模板.docx‘)
    for table_col in range(0,sheet.ncols):
        change_text(str(sheet.cell_value(0,table_col)),str(sheet.cell_value(table_row,table_col)))
        
    document.save(r‘C:\Users\13375\Desktop\python\%s合同.docx‘ % str(sheet.cell_value(table_row,0)))
    print("%s合同完成" % str(sheet.cell_value(table_row,0)))
        
               

批量生成n份不同的乙方合同

原文:https://www.cnblogs.com/tomhu/p/12343016.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!