いや、下記は自分用の備忘録ですのでお気になさらずに。
import openpyxl import sys import os import shutil import tempfile wb = openpyxl.Workbook() ws = wb.active c = ws.cell(row=5, column=5) c.value = 3.14 with tempfile.NamedTemporaryFile() as tmp: wb.save(tmp.name) tmp.seek(0) stream = tmp.read() print("Content-Type: application/octet-stream") print('Content-Disposition: attachment; filename="results.xlsx"') print("Content-Length: " + str(len(stream))) print('Cache-Control: max-age=0') print() sys.stdout.flush() sys.stdout.buffer.write(stream)