模板:
程式"
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 | from docxtpl import DocxTemplate, RichText tpl = DocxTemplate("AquaticTransTemplate.docx") context = { "table":[ { "date" : "1130527", "id" : 1011, "fish" : RichText("吳郭魚", color='00FF00', italic=True, size=20), "market" : RichText("斗南", color='0000FF', italic=False, size=20), "upper" : 82, "middle" : 71.6, "lower" : 56.2, "volume" : 1720.3, "average" : 70.6, }, { "date" : "1130527", "id" : 1019, "fish" : RichText("其他吳郭魚", color='00FF00', italic=True, size=20), "market" : RichText("台中", color='0000FF', italic=False, size=20), "upper" : 108, "middle" : 100, "lower" : 50, "volume" : 317.6, "average" : 99.6, }, ] } tpl.render(context) tpl.save("AquaticTransPapers.docx") |
執行結果:
沒有留言:
張貼留言