[884] How to generate automated Word documents by Python
ref: python-docx
ref: How to Generate Automated Word Documents with Python
ref: Automating Word Documents from Excel Using Python | ‘docxtpl’ Tutorial
ref: docxtpl快速上手使用,数据填入以及循环写入表格
ref: 探究Python中的文档自动化工具——docxtpl
ref: Python 第三方库之 docxtpl (处理word文档)
ref: docxtpl user manual
To install using pip:
pip install docxtpl
Usage:
from docxtpl import DocxTemplate doc = DocxTemplate("my_word_template.docx") context = {'company_name': "World company"} doc.render(context) doc.save("generated_doc.docx")
Example:
"test.docx"
Hello, my name is {{name}}. I am {{age}} years old now. I like playing {{sport_01}}, {{sport_02}}, and {{sport_03}}.
python script
doc = DocxTemplate('test.docx') context = {'name': 'Alex', 'age': 24, 'sport_01': 'badminton', 'sport_02': 'football', 'sport_03': 'basketball'} doc.render(context) doc.save('test_rendered.docx')
"test_rendered.docx"
Hello, my name is Alex. I am 24 years old now. I like playing badminton, football, and basketball.
This implementation can be found in Automating Word Documents from Excel Using Python | ‘docxtpl’ Tutorial.
About the generation of tables, please check my next blog. Cheers.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2020-09-22 【480】Keras实操