new2turbo ha scritto:
> Hi, I have been trying to use pyexcelerator to create excel
> spreadsheet... but am having trouble. I notice that u mentioned that
> it can create simple excel documents... Can u please tell me how.
>
Actually, generating the document is quite simple:
import pyExcelerator as pe
w = pe.Workbook()
ws = w.add_sheet('my sheet')
ws.write(0, 0, 'first header')
ws.write(1, 0, 'first cell')
...
ws.save(pathname)
Then, it's a matter of appropriately setting Content-Type headers before
return the file content to the browser.
If you'd rather NOT write to the filesystem, you can create a file in
memory, and just return it to the browser.
To do that, you can subclass WorkBook and add a method, say extract(),
to be used instead of save().
> class XlsDoc(CompoundDoc.XlsDoc):
> """
> An XlsDoc that returns the data instead of saving it
> """
> def extract(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()
>
> ret = []
> ret.append(self.header)
> ret.append(self.packed_MSAT_1st)
> ret.append(stream)
> ret.append(padding)
> ret.append(self.packed_MSAT_2nd)
> ret.append(self.packed_SAT)
> ret.append(self.dir_stream)
> return ''.join(ret)
>
> class ReturningWorkbook(pe.Workbook):
> def extract(self):
> doc = XlsDoc()
> doc.extract(self.get_biff_data())
I've not been using the above recipe since some time. YMMV.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---