from docxtpl import DocxTemplate
from openpyxl import load_workbook
import os
wb = load_workbook(r"F:\Desktop\个人任务汇总.xlsx")
ws = wb['个人任务汇总']
contexts = []
for row in range(2, ws.max_row + 1):
text1 = ws["A" + str(row)].value
text2 = ws["C" + str(row)].value
text3 = ws["D" + str(row)].value
text4 = ws["B" + str(row)].value
text5 = ws["E" + str(row)].value
context = {"列1": text1, "列2": text2, "列3": text3, "列4": text4, "列5": text5}
contexts.append(context)
contexts
# 创建要保存的文件夹
os.mkdir("./所有合同")
for context in contexts:
print(context)
tpl = DocxTemplate(r"F:\Desktop\上半年结算超30万承诺书.docx")
tpl.render(context)
tpl.save("./所有合同/{}的劳动合同.docx".format(context["列1"]))
读取excel数据批量填充world
最新推荐文章于 2024-07-23 16:23:28 发布