Writing to Excel

Amanjit Gill amanjit.gill at gmx.de
Sun Aug 4 13:53:45 CEST 2002


Hello..

If you really need to write to an Excel sheet you can set up an ODBC
connection to it and use mxODBC.

____________________________
Amanjit Gill
Software Entwickler
Medizinische und Bioinformatik der
Klinik für Frauenheilkunde und Geburtshilfe
030 450 564 326
Campus Charité Mitte
D-10098 Berlin

"Thomas Guettler" <zopestoller at thomas-guettler.de> schrieb im Newsbeitrag
news:3D11AFB7.9070803 at thomas-guettler.de...
> Chris wrote:
>
> > Hi I'm using a Python cgi script to write the contents of a table to
> > an Excel sheet. I retrieve all the information fine but it seems like
> > Excel doesnt want to print more than one line for me. It prints
> > 'headerLine' but nothing more. Why???
> >
> > ...
> > headerLine = "some crap"
> >
> > sys.stdout.write( Html.header( 'application/x-msexcel' ) )
> > print string.strip(headerLine)
> > allText = ""
>
>
> I do it with a different content-type. The code is attached, maybe
> it helps
>
>   thomas
>
> +++
>          if REQUEST:
>              REQUEST.RESPONSE.setHeader('Content-Type',
>                                         'application/vnd.ms-excel')
>
>          output=[]
>          output.append("<html><body><table border='1'>\n")
>          headers=list_of_all_properties.keys()
>          headers.sort()
>          output.append('<tr>')
>          for header in headers:
>              output.append('<th>%s</th>' % cgi.escape(header))
>          output.append('</tr>\n\n')
>          for line in lines:
>              output.append('<tr>')
>              for col in headers:
>                  value=line.get(col, '')
>                  if type(value) in [type([]), type(())]:
>                      new_value=[]
>                      for keyword in value:
>                          new_value.append(cgi.escape(keyword))
>                      value=string.join(new_value, '<br>')
>                  else:
>                      value=cgi.escape(value)
>                  output.append("<td>%s</td>" % value)
>              output.append('</tr>\n\n')
>          output.append("</table></body></html>")
>          return string.join(output)
> +++
>





More information about the Python-list mailing list