I tried to use nested loop to write data in my sheet and a column is missing in the final excel output if a the nested list is empty.
Here is the code I tried with the template template.xlsx :
from xlsxtpl.writerx import BookWriter
writer = BookWriter('template.xlsx')
writer.jinja_env.globals.update(dir=dir, getattr=getattr)
# Define the data that you want to fill into the template
data = {
'persons':[
{
'name': 'John',
'children':[
],
'age': 28
},
{
'name': 'Peter',
'children':[
{'name':'Ana'},
{'name':'Eve'}
],
'age': 49
}
],
}
writer.render_book(payloads=[data])
# Create a new workbook
writer.save("out.xlsx")
I tried to use nested loop to write data in my sheet and a column is missing in the final excel output if a the nested list is empty. Here is the code I tried with the template template.xlsx :
This is what was generated : out.xlsx.
the expected output would be an empty B2 cell and the data "28" in the C2 cell instead of the B2 cell.