XlsxWriter object save as http response to create download in Django

A little update on @alecxe response for Python 3 (io.BytesIO instead of StringIO.StringIO) and Django >= 1.5 (content_type instead of mimetype), with the fully in-memory file assembly that has since been implemented by @jmcnamara ({‘in_memory’: True}) ! Here is the full example : import io from django.http.response import HttpResponse from xlsxwriter.workbook import Workbook def your_view(request): … Read more

How to save a new sheet in an existing excel file, using Pandas?

Thank you. I believe that a complete example could be good for anyone else who have the same issue: import pandas as pd import numpy as np path = r”C:\Users\fedel\Desktop\excelData\PhD_data.xlsx” x1 = np.random.randn(100, 2) df1 = pd.DataFrame(x1) x2 = np.random.randn(100, 2) df2 = pd.DataFrame(x2) writer = pd.ExcelWriter(path, engine=”xlsxwriter”) df1.to_excel(writer, sheet_name=”x1″) df2.to_excel(writer, sheet_name=”x2″) writer.close() Here I … Read more