带有 docx 模板的动态 Table 行
Dynamic Table Rows with docx-template
美好的一天,
我正在尝试在 .docx 文件中动态填充 Table。 table 看起来像:
其中有 N 个项目 (1..N),每个项目有 N 行 (1..N),结构如下:
table_data = [
{
'title':'Proj1',
'rows':[
{'col1':'col1txt',
'col2':'col2txt',
'col3':'col3txt',
'col4':'col4txt',
'col5':'col5txt',
'col6':'col6txt'},
{'col1':'col1txt',
'col2':'col2txt',
'col3':'col3txt',
'col4':'col4txt',
'col5':'col5txt',
'col6':'col6txt'}
]
},
{..repeat..}
]
context={'table_data':table_data}
我目前正在使用 python-docx-template 库,关于嵌套 table 的在线示例很少。谁能指导我正确的方向?
如有任何帮助,我们将不胜感激。
解决方案:
我在以下位置找到了此嵌套 table 案例所需的信息:
https://github.com/elapouya/python-docx-template/blob/master/tests/templates/subdoc_tpl.docxhttps://github.com/elapouya/python-docx-template/blob/master/tests/templates/subdoc_tpl.docx
它的语法在:
https://github.com/elapouya/python-docx-template/blob/master/tests/dynamic_table.py
希望这对像我这样的人有帮助 :) 美好的一天!
处找到了此嵌套 table 案例所需的信息
它的语法位于:https://github.com/elapouya/python-docx-template/blob/master/tests/dynamic_table.py
美好的一天,
我正在尝试在 .docx 文件中动态填充 Table。 table 看起来像:
table_data = [
{
'title':'Proj1',
'rows':[
{'col1':'col1txt',
'col2':'col2txt',
'col3':'col3txt',
'col4':'col4txt',
'col5':'col5txt',
'col6':'col6txt'},
{'col1':'col1txt',
'col2':'col2txt',
'col3':'col3txt',
'col4':'col4txt',
'col5':'col5txt',
'col6':'col6txt'}
]
},
{..repeat..}
]
context={'table_data':table_data}
我目前正在使用 python-docx-template 库,关于嵌套 table 的在线示例很少。谁能指导我正确的方向?
如有任何帮助,我们将不胜感激。
解决方案:
我在以下位置找到了此嵌套 table 案例所需的信息: https://github.com/elapouya/python-docx-template/blob/master/tests/templates/subdoc_tpl.docxhttps://github.com/elapouya/python-docx-template/blob/master/tests/templates/subdoc_tpl.docx
它的语法在: https://github.com/elapouya/python-docx-template/blob/master/tests/dynamic_table.py
希望这对像我这样的人有帮助 :) 美好的一天!
它的语法位于:https://github.com/elapouya/python-docx-template/blob/master/tests/dynamic_table.py