We need to serve back not a file written on disk but a buffer in memory. We need this because we would serve the excel as a download from a website without passing from disk (to avoid time delay and disk space occupation).
So we wrapped CompoundDoc.XlsDoc and Workbook adding the def's to obtain a buffer in memory (using cStringIO).
We added to CompoundDoc.XlsDoc the def:
def getvalue(self, stream):
# 1. Align stream on 0x1000 boundary (and therefore on sector boundary)
padding = '\x00' * (0x1000 - (len(stream) % 0x1000))
self.book_stream_len = len(stream) + len(padding)
self.__build_directory()
self.__build_sat()
self.__build_header()
f = cStringIO.StringIO()
f.write(self.header)
f.write(self.packed_MSAT_1st)
f.write(stream)
f.write(padding)
f.write(self.packed_MSAT_2nd)
f.write(self.packed_SAT)
f.write(self.dir_stream)
return f.getvalue()
and in Workbook:
def getvalue(self):
doc = XlsDoc()
return doc.getvalue(self.get_biff_data())
Feel free to evaluate this add-ons.
I attached the .py that wraps the pyExcelerator.
Max M.
Wrap file of pyExcelerator
Logged In: YES
user_id=123639
Originator: NO
In the SVN trunk version there's a small change in CompoundDoc.py that handles this (checks if f has a "write" method and if so, just writes to f directly, otherwise assumes f is a filename and proceeds as before). Though, given the last release on this project was nearly 2 years ago, I'm not hopeful for a new release including this change any time soon. Still, there's nothing stopping anyone using the trunk version (I'm in a simliar situation to you, requiring the ability to generate and serve Excel files on the fly from the website, so I'm currently using the SVN trunk version to do just that).