excel_file = io.BytesIO()
workbook = xlsxwriter.Workbook(excel_file)
worksheet = workbook.add_worksheet()
# Code to populate the workbook
# Get some data to write to the spreadsheet.
data = [["nest", 'home', 'nest'],
[4, 30, 6],
[7, 8, 50]]
# Write some test data.
for row_num, columns in enumerate(data):
for col_num, cell_data in enumerate(columns):
worksheet.write(row_num, col_num, cell_data)
# Here comes the magic
workbook.close()
excel_file.seek(0)
new_zip.writestr( 'zip.xlsx', excel_file.getvalue() ) |