使用docxtpl模块自动填充doc文档

项目需求:根据网页端填写的信息,自动生成对应的doc文档

具体实现:使用docxtpl模块,返回一个属性字典,自动填充doc文档

官方文档:https://docxtpl.readthedocs.io/en/latest/

from docxtpl import DocxTemplate

doc = DocxTemplate("my_word_template.docx")
context = { 'company_name' : "World company" }
doc.render(context)
doc.save("generated_doc.docx")

猜你喜欢

转载自www.cnblogs.com/huaibin/p/12752894.html