UPD: the issue was fixed by the xlsxwriter author (works since 0.4.8 version). See the example.
Relying on my answer in this thread, here's what should work on GAE:
from xlsxwriter.workbook import Workbook
class IndexHandler(webapp2.RequestHandler):
def get(self):
book = Workbook(self.response.out)
sheet = book.add_worksheet('test')
sheet.write(0, 0, 'Hello, world!')
book.close()
# construct response
self.response.headers['Content-Type'] = 'application/ms-excel'
self.response.headers['Content-Transfer-Encoding'] = 'Binary'
self.response.headers['Content-disposition'] = 'attachment; filename="workbook.xls"'
But, it throws an error:
NotImplementedError: Only tempfile.TemporaryFile is available for use
because xlsxwriter
tries to write into the temp directory using tempfile.tempdir
anyway, see source of _store_workbook
method. And, GAE doesn't allow tempfile
module to be used in the project: see source, because, as you know, no access to the disk there.
So, a "vicious circle" here. Probably you should think about modifying _store_workbook
method to make it work completely in-memory. Or, may be you can mock
tempfile.tempdir
call on the fly and replace it with your own in-memory object.
Another option is to create an issue on xlsxwriter
issue tracker, I bet @jmcnamara has some good ideas on the subject.
Hope that helps.