File: cellbg.py

package info (click to toggle)
python-docx-template 0.20.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,404 kB
  • sloc: python: 1,742; makefile: 163
file content (42 lines) | stat: -rw-r--r-- 931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
Created : 2015-03-12

@author: Eric Lapouyade
"""

from docxtpl import DocxTemplate, RichText

tpl = DocxTemplate("templates/cellbg_tpl.docx")

context = {
    "alerts": [
        {
            "date": "2015-03-10",
            "desc": RichText("Very critical alert", color="FF0000", bold=True),
            "type": "CRITICAL",
            "bg": "FF0000",
        },
        {
            "date": "2015-03-11",
            "desc": RichText("Just a warning"),
            "type": "WARNING",
            "bg": "FFDD00",
        },
        {
            "date": "2015-03-12",
            "desc": RichText("Information"),
            "type": "INFO",
            "bg": "8888FF",
        },
        {
            "date": "2015-03-13",
            "desc": RichText("Debug trace"),
            "type": "DEBUG",
            "bg": "FF00FF",
        },
    ],
}

tpl.render(context)
tpl.save("output/cellbg.docx")