I am wondering if anyone knows how to use xlsxwriter in Google App Engine for Python. The documentation only shows how to open,write and save to a file. I've looked at workarounds using StringIO for other Excel libraries, but they don't seem transferable to xlsxwriter. The main reason seems to be that in other libraries you can supply a StringIO buffer, whereas in xlsxwriter you can only supply a string for the name of the file.
I have a basic solution in place using pyexcelerator but xlsxwriter is so much more feature rich that I'd like to use it, if possible.
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:
But, it throws an error:
because
xlsxwriter
tries to write into the temp directory usingtempfile.tempdir
anyway, see source of_store_workbook
method. And, GAE doesn't allowtempfile
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 canmock
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.