问题描述
我正在使用docxtpl创建模板字。但我徘徊着如何将两个模板docx合并为一个。 那里有一个很大的doc模板,还有另一个部分docx。我首先要修改部分docx。并将其放在{{mysubdoc}}
这样的大模板中from docxtpl import DocxTemplate
from docx.shared import Inches
tpl = DocxTemplate('templates/subdoc_tpl.docx')
sd = tpl.new_subdoc(docpath='templates/order_tpl.docx')
context = {
'mysubdoc': sd,}
tpl.render(context)
tpl.save('output/subdoc.docx')
有效。但是我想知道如何在渲染“ tpl”之前修改“ sd”模板? 像下面一样
from docxtpl import DocxTemplate
from docx.shared import Inches
tpl = DocxTemplate('templates/subdoc_tpl.docx')
sd = tpl.new_subdoc(docpath='templates/order_tpl.docx')
sdcontext = {
'customer_name': 'Eric','items': [
{'desc': 'Python interpreters','qty': 2,'price': 'FREE'},{'desc': 'Django projects','qty': 5403,{'desc': 'Guido','qty': 1,'price': '100,000,000.00'},],'in_europe': True,'is_paid': False,'company_name': 'The World Wide company','total_price': '100,000.00',}
sd.render(sdcontext)
context = {
'mysubdoc': sd,}
tpl.render(context)
tpl.save('output/subdoc.docx')
但是它确实起作用,原因是“ AttributeError:'Document'对象没有属性'render'”
期待您的回答
感谢前进
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)