:批量制作档案表,要从excel表格中将每个人的数据导入到docx档案
生活随笔
收集整理的這篇文章主要介紹了
:批量制作档案表,要从excel表格中将每个人的数据导入到docx档案
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
https://www.pythonf.cn/read/149081 Python自動將Excel數(shù)據(jù)填充到word的指定位置,Word,中
具體代碼如下:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from docxtpl import DocxTemplate from openpyxl import load_workbook import osdef replace(obj):if obj is None:obj = ''return obj# 加載要填入的數(shù)據(jù) wb = load_workbook(r"./detailContent.xlsx") ws = wb['sheet1']contexts = [] for row in range(2, ws.max_row + 1):name = ws["A" + str(row)].value#c_name = ws["B" + str(row)].valueziduanName = ws["C" + str(row)].value# num = ws["D" + str(row)].value# time = ws["E" + str(row)].value# time = str(time)[:-9]# money = ws["F" + str(row)].value# address = ws["G" + str(row)].value# replace_peo = ws["H" + str(row)].value# context = {"name": name, "c_name": c_name, "code": code, "num": num, "time": time,# "money": money, "address": address, "replace_peo": replace_peo}context = {"name":name,"ziduanName":ziduanName}contexts.append(context) #contexts print(contexts) print(len(contexts)) # 創(chuàng)建要保存的文件夾 os.mkdir("./word1")for context in contexts:print(context)tpl = DocxTemplate(r"./model.docx")tpl.render(context)tpl.save("./word1/數(shù)據(jù)表-{}.docx".format(context["name"]))總結(jié)
以上是生活随笔為你收集整理的:批量制作档案表,要从excel表格中将每个人的数据导入到docx档案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 容器的使用和创建虚拟环境 vituale
- 下一篇: 1数组中重复的数字-面试题目3