0

Good morning,

inside my application I'm trying to download multiple - id's are stored inside a list - excel-sheets together with openpyxl. For a single file I'm using this way:

qs = Data.objects.get(id=pk)
df = read_frame(qs)
...
wb = Workbook()
...
ws = wb.get_sheet_by_name('Example')
for row in dataframe_to_rows(df, index=False, header=False):
    ws.append(row)    
...
response = HttpResponse(content=save_virtual_workbook(wb), content_type='application/ms-excel')
response['Content-Disposition'] = f'attachment; filename={file_text}.xlsx'

return response

Of course a return inside a for-loop would break it, but is there any other way to accomplish this?

Thank you and have a great day!

finethen
  • 385
  • 1
  • 4
  • 19
  • 1
    use generator(`yield response`) and [this](https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do) will help in undesrtanding `yield` keyword in python – deadshot Aug 12 '21 at 07:00
  • Clarification would be much appreciated. Are you trying to get values out of a spreadsheet for use elsewhere in the application? – James Geddes Aug 12 '21 at 07:03

0 Answers0