code: def toxls(tbl, filename, sheet, encoding=None, style_compression=0,
            styles=None):
      
  
      import xlwt
      if encoding is None:
          encoding = locale.getpreferredencoding()
      wb = xlwt.Workbook(encoding=encoding, style_compression=style_compression)
      ws = wb.add_sheet(sheet)
  
      if styles is None:
          # simple version, don't worry about styles
          for r, row in enumerate(tbl):
              for c, v in enumerate(row):
                  ws.write(r, c, label=v)
      else:
          # handle styles
          it = iter(tbl)
          hdr = next(it)
          flds = list(map(str, hdr))
          for c, f in enumerate(flds):
              ws.write(0, c, label=f)
              if f not in styles or styles[f] is None:
                  styles[f] = xlwt.Style.default_style
          # convert to list for easy zipping
          styles = [styles[f] for f in flds]
          for r, row in enumerate(it):
              for c, (v, style) in enumerate(izip_longest(row, styles,
                                                          fillvalue=None)):
                  ws.write(r+1, c, label=v, style=style)
  
      wb.save(filename)
docs: Write a table to a new Excel .xls file.