'Jinja2 template in Excel file

I am new to jinja and need help in using jinja template in excel file.

I have my payload as

info = {'company_name': u'abcd', 'report_date': u'Employee master report for April-2022', 'column_name' :['esalary','ename','ecode']}

Now I have created my excel template as

JINJA_SAMPLE_TEMPLATE

when I run my code all the column names will come at cell A3. But I want the column names in different cells. 'esalary' in A3, 'ename' in B3 and 'ecode' in C3.How can I achieve this?

Here is the code:

import os
from xlsxtpl.writerx import BookWriter

def write_test():
    pth = os.path.dirname(__file__)

    fname = os.path.join(pth, 'sample.xlsx')

    writer = BookWriter(fname)
    writer.jinja_env.globals.update(dir=dir, getattr=getattr)

    info = {'company_name': u'abcd', 'report_date': u'Employee master report for April-2022', 'column_name' :['esalary','ename','ecode']}

    payloads = [info]
    writer.render_book(payloads=payloads)
    fname = os.path.join(pth, 'result00.xlsx')
    writer.save(fname)

if __name__ == "__main__":
    write_test()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source