File: dynamic_table.py

package info (click to toggle)
python-docx-template 0.16.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,296 kB
  • sloc: python: 1,552; makefile: 164
file content (15 lines) | stat: -rw-r--r-- 495 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from docxtpl import DocxTemplate

tpl = DocxTemplate('templates/dynamic_table_tpl.docx')

context = {
    'col_labels': ['fruit', 'vegetable', 'stone', 'thing'],
    'tbl_contents': [
        {'label': 'yellow', 'cols': ['banana', 'capsicum', 'pyrite', 'taxi']},
        {'label': 'red', 'cols': ['apple', 'tomato', 'cinnabar', 'doubledecker']},
        {'label': 'green', 'cols': ['guava', 'cucumber', 'aventurine', 'card']},
    ],
}

tpl.render(context)
tpl.save('output/dynamic_table.docx')