Cannot write to StringIO in 2.6.2
Created originally on Bitbucket by patricebertrand (Patrice B)
It used to be possible to write to a StringIO object, which was the way to return an xlsx file in a server environment where creating temporary files is not allowed, such as Google App Engine.
Having created a workbook, I would simply do this:
si = StringIO.StringIO()
wb.save(si)
response = make_response(si.getvalue())
response.headers["Content-Disposition"] = "attachment; filename=" + file_name
response.headers["Content-type"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
I tried to migrate to openpyxl 2.6.2 to have the benefit of new or improved features, but I cannot find an equivalent of this.
I thought this would do the job:
sio = StringIO.StringIO()
archive = ZipFile(sio, 'w', ZIP_DEFLATED, allowZip64=True)
ew = ExcelWriter(wb, archive)
ew.write_data()
However WorksheetWriter
calls create_temporary_file()
, which uses a NamedTemporaryFile
object, which is an actual temp file, i.e. on disk, which is not allowed in App Engine. So this fails with error NotImplementedError: Only tempfile.TemporaryFile is available for use
Is there a way to have openpyxl 2.6.2 work within the constraints of App Engine (which are not unique) ?