code: def make_csv(self):
          
          import csv
          try:
              from StringIO import StringIO  # Python 2.7
          except ImportError:
              from io import StringIO
  
          out = StringIO()
          writer = csv.writer(out, delimiter='|', lineterminator='\n', quoting=csv.QUOTE_MINIMAL)
  
          if self.function == 'total':
              writer.writerows(self.results)                
  
          elif self.function == 'top':
              rows = [['Value', self.headers.strip('"')]]
              if self.results[0] is not None:
                  for res in self.results:
                      if res is not None:
                          rows.append(tuple([res[0], ','.join(res[1])]))
                  writer.writerows(rows)
                  
          elif self.function == 'table':
              rows = [[header.strip('"') for header in re.split('\s*,\s*', self.headers)]]
  
              for res in sorted(self.results, key=lambda x: x[0]):
                  row = list(res[:-1])
                  lastcol = get_fmt_results(res[-1], limit=10)
                  if lastcol[-1][0] == '[' and lastcol[-1][-1] == ']':
                      row.append(u'{0} {1}'.format(u', '.join(lastcol[:-1]), lastcol[-1]))
                  else:
                      row.append(u', '.join(lastcol))
                  rows.append(row)
              writer.writerows(rows)
  
          self.csv = out.getvalue()
docs: Get the text representation of a report element as csv.