I am used to creating a spreadsheet in the following way:
wbk = xlwt.Workbook()
earnings_tab = wbk.add_sheet('EARNINGS')
wbk.save(filepath)
Is there any way to not save to file to a filepath, and instead write it on-the-fly to a user who downloads the file? Or do I need to save it as a tmp file and then serve that to the user?
this is what i use in Django:
To quote the documentation for the
.save()
method ofxlwt
:Modified example:
Some may suggest you use
cStringIO
instead ofStringIO
, but be forewarned thatcStringIO
when last I checked does not properly handle Unicode.It's perhaps also worth noting that
StringIO
is replaced in Python 3 byio
.