[Zope] Re: export to excel
Ayhan Ergul
ergul@ccs.neu.edu
Wed, 14 Feb 2001 12:04:39 -0500 (EST)
Here's some crude code to do what you want. Note that some lines are
broken by my emailer and excel may be picky about extra white space.
yourMethodName.csv:
Content-type: application/ms-excel
<dtml-let query="YourZSQLQuery()"
names="query.names">
<dtml-in names>
<dtml-var "escape_csv(inStr=_['sequence-item'],
REQUEST=REQUEST)"><dtml-unless sequence-end>,</dtml-unless>
</dtml-in><dtml-var "'\r'">
<dtml-in query>
<dtml-in sequence-item>
<dtml-if sequence-item><dtml-var
sequence-item><dtml-unless sequence-end>,</dtml-unless>
</dtml-in><dtml-var "'\r'">
</dtml-in>
</dtml-let>
escape_csv:
<dtml-call "REQUEST.set('outStr', '')">
<dtml-if "_.chr(34) in inStr">
<dtml-call "REQUEST.set('outStr', _.chr(34) +
_.string.join(_.string.split(inStr, _.chr(34)), _.chr(34)+_.chr(34)) +
_.chr(34))">
<dtml-else>
<dtml-if "',' in inStr">
<dtml-call "REQUEST.set('outStr', _.chr(34) + inStr + _.chr(34))">
<dtml-else>
<dtml-call "REQUEST.set('outStr', inStr)">
</dtml-if>
</dtml-if>
<dtml-return "REQUEST['outStr']">
Ayhan Ergul <ergul@acm.org>