python依据模板生成word文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python依据模板生成word文件相关的知识,希望对你有一定的参考价值。

参考技术A

1、安装包

pip install docxtpl


2、制作模板

3、实现源码

from docxtpl import DocxTemplate

stu = DocxTemplate('student.docx')
inf = 'sno': '20201105001', 'sname': '李磊', 'sage': '20', 'ssex': '男'
stu.render(inf)
stu.save('学生卡.docx')


4、实现结果

以上是关于python依据模板生成word文件的主要内容,如果未能解决你的问题,请参考以下文章