-1
views
def export_to_xls(request):
obitos = Obito.objects.all()
response = HttpResponse(content_type='application/vnd.openxmlformats- officedocument.spreadsheetml.sheet',)
response['Content-Disposition'] = 'attachment; filename={date}-movies.xlsx'.format(date=datetime.now().strftime('%Y-%m-%d'),)
workbook = Workbook()
worksheet = workbook.active
worksheet.titulo = "teste-Obitos"
columns = [
'nome_obito',
'idade_obito',
]
row_num = 1
for col_nome, col_idade in enumerate(columns, 1):
cell = worksheet.cell(row=row_num, column=col_idade)
cell.value = col_idade
for obito in obitos:
row_num += 1
row = [
obito.nome_obito,
obito.col_idade
]
for col_num, cell_value in enumerate(row, 1):
cell = worksheet.cell(row=row_num, column=col_num)
cell.value = cell_value
workbook.save(response)
return response
I have this problem in the generation of xls! Any suggestions? Thank you.
Hello @sedarky avoid placing images in your questions, put the error message in Code Sample in the "{ }" field so we can help you.
– Izak Mandrak