word模板填值
1、手動做好模板——my_test.docx的內容:
我的名字叫做{{ name }}。
2、python代碼:
# test_fill_word.py
# python -m pip install docxtpl
from docxtpl import DocxTemplate
tpl = DocxTemplate('my_test.docx')
context = {
'name': 'lovecjy'
}
tpl.render(context)
tpl.save('my_test1.docx')
運行上述代碼,會在腳本所在目錄生成填好數據word——my_test1.docx。
以上。