There are small typos in: - docs/index.rst - docxtpl/__main__.py - docxtpl/template.py - tests/embedded.py Fixes: - Should read `surrounding` rather than `surronding`. - Should read `rendering` rather than `rendring`. - Should read `providing` rather than `provinding`. - Should read `optionally` rather than `optionnally`. - Should read `optional` rather than `optionnal`. - Should read `necessary` rather than `neccessary`. - Should read `existing` rather than `exsting`. - Should read `embedded` rather than `embdded`. - Should read `dictionaries` rather than `dictionnaries`. - Should read `cleaning` rather than `cleanning`. - Should read `catches` rather than `cacthes`. Signed-off-by: Tim Gates <tim.gates@iress.com>
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
'''
|
|
Created : 2017-09-09
|
|
|
|
@author: Eric Lapouyade
|
|
'''
|
|
|
|
from docxtpl import DocxTemplate
|
|
|
|
# rendering the "dynamic embedded docx":
|
|
embedded_docx_tpl = DocxTemplate('templates/embedded_embedded_docx_tpl.docx')
|
|
context = {
|
|
'name': 'John Doe',
|
|
}
|
|
embedded_docx_tpl.render(context)
|
|
embedded_docx_tpl.save('output/embedded_embedded_docx.docx')
|
|
|
|
|
|
# rendering the main document :
|
|
tpl = DocxTemplate('templates/embedded_main_tpl.docx')
|
|
|
|
context = {
|
|
'name': 'John Doe',
|
|
}
|
|
|
|
tpl.replace_embedded(
|
|
'templates/embedded_dummy.docx', 'templates/embedded_static_docx.docx'
|
|
)
|
|
tpl.replace_embedded(
|
|
'templates/embedded_dummy2.docx', 'output/embedded_embedded_docx.docx'
|
|
)
|
|
|
|
# The zipname is the one you can find when you open docx with WinZip, 7zip (Windows)
|
|
# or unzip -l (Linux). The zipname starts with "word/embeddings/".
|
|
# Note that the file is renamed by MSWord, so you have to guess a little bit...
|
|
tpl.replace_zipname(
|
|
'word/embeddings/Feuille_Microsoft_Office_Excel3.xlsx', 'templates/real_Excel.xlsx'
|
|
)
|
|
tpl.replace_zipname(
|
|
'word/embeddings/Pr_sentation_Microsoft_Office_PowerPoint4.pptx',
|
|
'templates/real_PowerPoint.pptx',
|
|
)
|
|
|
|
tpl.render(context)
|
|
tpl.save('output/embedded.docx')
|