python——word模板中填值


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。

以上。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM