1👍
openpyxl provides a function to save a file to a StringIO
object:
from openpyxl.writer.excel import save_virtual_workbook
stream = save_virtual_workbook(wb)
However, for larger files it might be preferable to save to somewhere in the file system and let the http server handle the download.
Source:stackexchange.com