首先安装docxtpl
$ pip install docxtpl
python代码如下:
from docxtpl import DocxTemplate
tpl = DocxTemplate('劳动合同.docx')
#这些字段从csv中获取
context = {
"name": name,
"department": department,
"position": position,
"time": time,
"id": id_card,
"addr": addr,
}
tpl.render(context)
tpl.save("{}的劳动合同.docx".format(name))